Guardrails are programmable checks on user input before it reaches the model (jailbreaks, prompt injection, off-topic and banned requests) and on model output before it reaches the user or a tool (schema, policy, hallucination, unsafe action).
Input rails and output rails
Frameworks such as NVIDIA NeMo Guardrails, Guardrails AI and Llama Guard / Prompt Guard wrap the model in checks. On input they combine regular expressions, classifiers and small-model judges. A violating input is rejected or rewritten, so flagged prompts that try to bypass restrictions do not reach the model.
On output they check structure, run moderation classifiers, and verify that the response is grounded in retrieved context. The system can then block the output, redact sensitive information, or regenerate the response.
- Inspect user input before model processing.
- Validate model output before delivery to the user or a tool.
- Use regular expressions and classifiers for the checks.
- Version the guardrails separately from the prompts.
- Tune thresholds to your risk tolerance.
Policies are written in formats such as Colang, YAML or custom code. That lets you version and test them independently of the prompts, which makes the system auditable and lets it adapt to new threats without changing the model.
Why rules in the system prompt get bypassed
A common first attempt is a system prompt that says "never do X". Users can get around it with prompt injection. Rules inside a prompt are also hard to audit, so you cannot easily tell what was allowed or rejected.
External guardrails run outside the model, apply the same checks whatever the user says, so the user cannot talk the model out of a rule. They log what was blocked and why, which gives you an audit trail.
Guardrails as a probabilistic WAF
Guardrails resemble input validation plus an API gateway or a Web Application Firewall. The difference is that the attacker input is natural language and the service, the model, is nondeterministic. The guardrails rely on probabilistic classifiers that estimate how likely an input or output is to be harmful, so they produce false positives and false negatives and need tuning.
| Deployment | Guardrail level |
|---|---|
| Public-facing or agentic system | Full input and output guardrails |
| Internal tool in a low-risk setting | A lighter touch, such as output schema validation |
Example scenario: 30% of inputs flagged as policy violations
Suppose guardrails flag 30% of user input. The figure is illustrative. They may be too strict or misconfigured, and a policy engine that is out of date can misclassify legitimate input.
- Check the guardrail configuration for accuracy and relevance.
- Log the flagged inputs and look for patterns.
- Compare the policy engine's update frequency with current guidelines.
Adjust the guardrail parameters to cut false positives while keeping the needed restrictions. The cost is that some inappropriate input may get through. Monitor the flag rate and user complaints, and set an acceptable complaint rate to steer further tuning.