A model's training and system prompt make good behaviour likely. Guardrails make the application check. They are separate pieces of code or classifier models that run before the model sees a request, after it answers, and before any action it proposes is carried out. When a check fails, the guardrail blocks the request, redacts or rewrites the output, retries, or hands over to a person.
Guardrails don't make a model safe on their own. They are one layer, alongside permissions enforced in your own code, testing and monitoring.
Types of guardrails
Input guardrails check what comes in:
- topic filters that keep a banking assistant on banking
- detection of prompt injection in user messages and retrieved documents
- redaction of personal data, such as Aadhaar, PAN or card numbers, before text goes to a model provider
- length and rate limits
Output guardrails check what the model produces:
- schema validation for structured output, with a retry if the JSON doesn't parse
- grounding checks that flag claims the sources don't support, a defence against hallucinations
- content filters for harmful, abusive or off-brand text
- comparisons with your own data, such as "does this policy number exist?"
Action guardrails apply to AI agents:
- an allow-list of tools for each step and each user
- limits on amounts, recipients and the number of steps
- human approval for payments, emails and record changes
Example: guardrails on an insurance claims assistant
A customer-facing assistant answers questions about a policyholder's claim. The request path looks like this:
1. Input "What's the status of claim CLM-20931? My PAN is ABCDE1234F"
-> PAN redacted to [PAN] before the model call
-> claim CLM-20931 belongs to the logged-in user? yes
2. Model drafts an answer from the claim record and policy wording
3. Output -> JSON schema valid? yes
-> status and dates match the claim record? no:
draft says "approved", record says "under review"
-> retry with the record quoted; second draft passes
4. Action customer asks to change the payout bank account
-> tool needs OTP step-up and staff review; the agent can't do it alone
The model got the status wrong once. A simple check against the source record caught it before the customer saw it.
Tools for building guardrails
- Your own code. Schema validation, allow-lists, permission checks and comparisons with source data are the cheapest and most reliable guardrails.
- Cloud services. Amazon Bedrock Guardrails offers content filters, denied topics, sensitive-information filters and contextual grounding checks. Microsoft Foundry groups content filters and Prompt Shields under "guardrails and controls".
- Open-source options. NVIDIA NeMo Guardrails, Guardrails AI and safety classifier models such as Meta's Llama Guard can run inside your own environment.
- Agent frameworks. Several let you attach input and output guardrails to an agent. Our agent framework comparison covers them.
Common mistakes
- Rules that live only in the prompt. "Never reveal account data" in a system prompt is a request, not a control.
- Over-blocking. A strict filter that refuses legitimate questions drives users away. Measure false positives as well as misses with LLM evaluation.
- Checking text but not actions. In an agent, the riskiest failure is a tool call, not a sentence.
- Ignoring latency. Each model-based check adds time. Run cheap code checks first and run independent checks in parallel.
Our guide to taking an LLM feature from demo to production shows where guardrails fit alongside evaluation and monitoring.