AI
AI Guardrails: What They Are and How to Add Them
AI guardrails are checks around a model that block harmful input, unsafe output and risky actions. Types, examples, LLM guardrail tools and setup.
AI guardrails are the checks and limits you put around an AI model so it stays safe, accurate and on task. They inspect what goes in (blocking prompt injection, personal data or off-topic requests), what comes out (catching harmful content, leaked secrets, made-up facts or broken formats) and what an AI agent is allowed to do (limiting tools, spending and actions that need human approval). Models have some safety training built in, but guardrails are the layer you control, tuned to your product, users and risks.
This guide explains what AI guardrails are, how they work, the main types, AI guardrails examples for common risks, LLM guardrails tools such as NeMo Guardrails, Guardrails AI and Llama Guard, guardrails for AI agents, a worked example, and how to add guardrails without ruining speed or usefulness.
What Are AI Guardrails?
Think of a language model as a capable but unpredictable worker. Guardrails are the rules and checks around that worker:
- Before the model: check the request. Is it allowed? Does it contain personal data that shouldn't be sent to the model? Is it trying to override instructions?
- After the model: check the answer. Is it safe, on topic, in the right format, and supported by the sources it was given?
- Around actions: if the model can use tools, decide which actions it can take alone and which need approval.
Guardrails complement, but don't replace, the model provider's own safety training. The provider protects against general harms; your guardrails protect against the risks specific to your app, such as a support bot promising refunds it can't give, or an internal assistant revealing salary data.
How AI Guardrails Work
Most guardrails use one or more of these techniques:
| Technique | How it works | Good for | Trade-off |
|---|---|---|---|
| Rules and patterns | Keyword lists, regular expressions, allow and block lists | Card numbers, banned terms, URLs | Fast, but easy to evade and brittle |
| Classifier models | A small model labels text as safe or unsafe by category | Toxicity, self-harm, jailbreak attempts | Fast, but needs tuning to avoid false alarms |
| LLM-as-judge | A second model checks the output against criteria | Tone, policy compliance, factual support | Flexible, but slower and costs more |
| Schema validation | Check output matches a required structure | JSON, forms, function arguments | Reliable for structure, not meaning |
| Grounding checks | Compare the answer with the retrieved sources | Hallucinations in RAG apps | Adds latency; not perfect |
| Permissions and limits | Restrict tools, data access, rates and budgets | Agents, cost control | Requires good system design |
| Human review | A person approves before something happens | Payments, emails, deletions | Slow, so use only where it matters |
In practice, guardrails are layered: cheap, fast checks run on everything, and slower checks run only when needed.
Types of AI Guardrails
- Input guardrails: detect prompt injection and jailbreak attempts, filter abusive content, remove or mask personal data, enforce length limits.
- Topic and dialog guardrails: keep the assistant to its job (a banking bot shouldn't give medical advice) and steer conversations along allowed paths.
- Retrieval guardrails: control which documents a user's question can retrieve, based on their permissions, and filter retrieved text for hidden instructions.
- Output guardrails: block harmful content, check facts against sources, redact secrets and personal data, enforce format and brand rules.
- Action guardrails: for agents, limit which tools can run, with what arguments, how often, and which actions require approval.
- Operational guardrails: rate limits, spending caps, logging and alerting.
- Governance guardrails: company policies on which AI tools may be used and for what; see our guide to an AI policy for companies.
AI Guardrails Examples
AI guardrails examples for common risks:
| Risk | Example | Guardrail |
|---|---|---|
| Prompt injection | A web page tells the assistant to ignore its instructions | Injection classifier on retrieved text; treat it as data; limit tools |
| Data leakage | A user asks the HR bot for a colleague's salary | Retrieval permissions; output check for personal data |
| Off-topic use | People use a support bot as free general-purpose AI | Topic classifier; polite refusal with a redirect |
| Harmful content | Requests for dangerous instructions or harassment | Moderation classifier on input and output |
| Hallucination | The bot invents a refund policy | Grounding check against policy documents; "I don't know" fallback |
| Wrong commitments | The bot promises a discount it can't offer | Output rules for commitments; escalation to a person |
| Broken output | The model returns invalid JSON for an API | Schema validation with automatic retry |
| Risky actions | An agent deletes records or sends emails | Tool allowlist; human approval; dry-run mode |
| Runaway cost | A loop calls the model thousands of times | Step limits, budgets, rate limits |
Prompt injection deserves special attention, because no single check stops it reliably; our guide to prompt injection explains why.
LLM Guardrails Tools
Popular LLM guardrails tools:
| Tool | Type | What it does |
|---|---|---|
| NeMo Guardrails (Nvidia) | Open-source toolkit | Programmable "rails" for input, output, dialog, retrieval and execution, written in its Colang language plus configuration |
| Guardrails AI | Open-source Python library | Validators (from a public hub) that check and fix inputs and outputs, such as PII detection or format checks |
| Llama Guard (Meta) | Open-weight safety model | Classifies prompts and responses into safety categories; Llama Guard 4, released in April 2025, is a 12-billion-parameter multimodal version |
| Amazon Bedrock Guardrails | Managed cloud service | Content filters, denied topics, PII masking and contextual grounding checks; usable with models outside Bedrock through its API |
| Azure AI Content Safety | Managed cloud service | Content moderation and "Prompt Shields" to detect prompt injection |
| OpenAI Moderation API | Hosted classifier | Free moderation endpoint that flags harmful text and images |
| Open-source classifiers | Small models | Prompt-injection, toxicity and PII detectors you can run yourself |
NeMo Guardrails
NeMo Guardrails is Nvidia's open-source toolkit for adding programmable rails around a language model app. You define flows and rules, such as which topics the bot can discuss, how it should respond to certain requests, and which checks run on input and output, and the toolkit sits between your app and the model. It's flexible and good for conversational apps with strict dialog rules, though it takes time to learn.
Choosing a tool
- On AWS or Azure and want minimal setup: use the managed service.
- Need full control or on-premises: combine open-source tools such as Llama Guard, Guardrails AI validators and NeMo Guardrails.
- Simple app: a moderation endpoint, an injection classifier, schema validation and a few rules may be enough.
Guardrails for AI Agents
Guardrails for AI agents matter most, because agents act rather than just talk. Key controls:
- Least privilege: give each agent only the tools and data it needs; read-only by default.
- Tool allowlists and argument checks: for example, an agent may send email only to addresses in your company's domain.
- Human approval for high-impact actions: payments, deletions, external messages, production changes.
- Budgets: limits on steps, tokens, tool calls and spending per task.
- Sandboxing: run code and browsers in isolated environments with limited network access.
- Separate untrusted content from instructions: text from web pages, emails and documents is data, never commands.
- Logging and monitoring: record every action for review and alert on unusual behaviour.
If your agents connect to tools through the Model Context Protocol, our guide to MCP security covers the extra risks.
A Worked Example: Guardrails for a Support Bot
Here's an illustrative guardrail stack for a customer-support assistant that answers from a help centre and can look up orders:
| Step | Guardrail | Typical approach | Cost in latency |
|---|---|---|---|
| 1 | Block abuse and obvious jailbreaks | Moderation and injection classifiers | Small |
| 2 | Mask payment card numbers and IDs in the message | Pattern rules and a PII detector | Very small |
| 3 | Keep to support topics | Topic classifier or rules in the system prompt | Small |
| 4 | Only retrieve the customer's own orders | Permission check in the order-lookup tool | None (system design) |
| 5 | Answer from help-centre sources | Retrieval plus instructions to cite sources | Part of normal generation |
| 6 | Check the answer is supported by sources | Grounding check or lightweight judge model | Moderate |
| 7 | Block promises outside policy | Rules for refund amounts and commitments | Small |
| 8 | Escalate when unsure | Hand off to a person with a summary | None |
| 9 | Log everything | Store inputs, outputs and guardrail decisions | None for the user |
Notice how much protection comes from design (permissions, escalation, logging) rather than clever filters. Run fast checks on every message, and reserve slower checks, such as grounding with a judge model, for answers that contain commitments or policy details.
Guardrails in RAG Apps
Apps that answer from documents need a few guardrails of their own:
- Permission-aware retrieval: only search documents the user is allowed to see. Filtering after retrieval is too late if the model has already read restricted text.
- Injection filtering on retrieved text: documents and web pages can contain hidden instructions; scan them or treat them strictly as data.
- Grounding and citations: require answers to cite sources, and check that each claim is supported. If not, answer "I couldn't find that" instead of guessing.
- Freshness: label or exclude outdated documents so the model doesn't quote last year's policy.
Guardrails vs Moderation vs Alignment
These terms overlap but aren't the same:
| Term | What it means | Who controls it |
|---|---|---|
| Alignment and safety training | How the model itself was trained to behave | The model provider |
| Moderation | Classifying content as harmful or allowed | Provider or app builder |
| Guardrails | All the checks, limits and rules around the model in your app | The app builder |
| Governance and guidelines | Company policies on how AI is used | The organisation |
Guardrails are where your product's specific rules live. Moderation is usually one component of them.
How to Measure Guardrails
Treat guardrails like any other feature and measure them:
- Catch rate: how many bad inputs or outputs the guardrail stops, measured on a test set of known attacks and mistakes.
- False-positive rate: how often it blocks legitimate requests. High false positives frustrate users.
- Latency added per check and in total.
- Cost of any extra model calls.
- Escape rate in production: problems that got through, found through user reports and log reviews.
Keep a growing test set from red-teaming and real incidents, and run it whenever you change prompts, models or guardrail settings.
Guardrails and Regulation
Guardrails are also how organisations show they manage AI risk. Frameworks that shape them include the NIST AI Risk Management Framework in the US, the OWASP Top 10 for large language model applications, which lists risks such as prompt injection and sensitive information disclosure, and the EU AI Act, which requires risk management and human oversight for high-risk AI systems. Documenting your guardrails, tests and monitoring makes audits and customer security reviews much easier.
How to Add AI Guardrails
- List your risks: what could go wrong for your users, your company and third parties? Rank by likelihood and impact.
- Start with design: permissions, limited tools, clear escalation paths. These are the strongest guardrails.
- Add input and output checks for the top risks, starting with fast ones.
- Write clear refusal and fallback messages so blocked users know what to do next.
- Test with red-teaming: try to break your app with injection attempts, edge cases and misuse. Turn the failures into test cases.
- Measure false positives and negatives: a guardrail that blocks legitimate users is a product bug.
- Monitor in production: track how often guardrails fire, review samples, and update rules as you learn.
- Revisit when models change, since a new model may behave differently.
Common Mistakes
- Relying on the system prompt alone. Instructions help but are easy to override.
- One giant filter instead of layered, targeted checks.
- Blocking too much, which frustrates users and pushes them to unofficial tools.
- Ignoring latency: stacking several slow checks on every message makes the product feel broken.
- No monitoring: guardrails that never get reviewed drift out of date.
- Forgetting actions: focusing on what the model says while giving it unlimited tools.
FAQ
What are AI guardrails?
AI guardrails are checks and limits around an AI model that keep it safe and on task. They filter inputs, check outputs and restrict actions, for example blocking prompt injection, masking personal data, catching hallucinations and requiring approval before an agent takes risky actions.
What are examples of AI guardrails?
Examples include moderation filters for harmful content, prompt-injection detectors, PII masking, topic restrictions, grounding checks against source documents, JSON schema validation, tool permissions for agents, spending limits and human approval for payments or emails.
What is NeMo Guardrails?
NeMo Guardrails is an open-source toolkit from Nvidia for adding programmable guardrails to language model applications. It lets developers define rails for input, output, dialog flow, retrieval and tool execution.
Do AI guardrails slow down responses?
They can. Fast checks like rules and small classifiers add little delay, while checks that use a second language model add more. Most apps layer fast checks on every message and use slower ones only where the risk justifies it.
Are guardrails enough to make AI safe?
No single layer is enough. Guardrails work best combined with careful system design (limited permissions and tools), model provider safety features, testing, monitoring and human review for high-stakes decisions.