Production Guide 24 of 25
Guardrails: keeping LLM systems safe and correct
Guardrails are the checks outside the model that limit what goes in, what comes out, and what the system may do. Assume the model will be fooled, and design so that a fooled model cannot cause real harm.
Key takeaways
- Prompt injection has no reliable fix today. Design so a fooled model cannot do damage: least privilege, deterministic checks at every tool call, and approval for risky actions.
- Injection classifiers raise attacker cost but are not a security boundary. In a 2025 study, adaptive attacks beat most of 12 published defenses more than 90% of the time.
- Correctness is a guardrail too. Validate outputs in code, ground factual answers in sources, and encode output for wherever it is rendered or executed.
- Budget guardrails like any production dependency: cascade cheap checks before expensive ones, track false positives, and decide whether users may see text before checks finish.
- Test guardrails the way attackers will, adaptively and with full knowledge of your defenses, and keep every successful attack in your eval suite.
On this page 6 sections
A customer asks your support bot about a refund, and it confidently describes a policy that does not exist. An agent summarizing an inbox reads an email written by an attacker and does what the email says. A chat window renders a model-generated image link that quietly carries private data to someone else’s server.
None of these needs an exotic exploit. Each needs only a large language model (LLM) wired into a product with too few checks around it. Guardrails are those checks: any control outside the model that limits what goes in, what comes out, or what the system is allowed to do.
The August 2026 risk list from the Open Worldwide Application Security Project (OWASP) tells teams to stop hunting for a trick-proof model and to build systems that stay safe after a trick works. Its authors put the goal plainly:
“when the model is fooled, and it will be, nothing important breaks” — Steve Wilson and Rock Lambros, project leads, OWASP Top 10 for LLM Applications 2026
This guide shows how to build for that, and what it costs.
What is a guardrail actually protecting against?
Guardrails do five distinct jobs, and each needs different tools:
- Misuse. Users requesting harmful content, or the model producing it.
- Manipulation. Prompt injection and jailbreaks: text that redirects the model, typed by a user or hidden in a document, web page, image, or tool result.
- Leakage. Personal data, secrets, system prompts, retrieved documents, or agent memory reaching people who should not see them.
- Incorrectness. Fluent answers that are wrong: invented policies, unsupported claims, tool calls with bad arguments.
- Unsafe handling. Downstream code trusting model output, by rendering it as a web page, running it as a database query, or fetching the links it contains.
The 2026 edition of OWASP’s Top 10 for LLM Applications, published in early August 2026, keeps prompt injection first and sensitive information disclosure second. Excessive agency, meaning a model holding more permissions or autonomy than its job needs, climbs from sixth to third. Improper output handling falls from fifth to tenth.
For the first time, OWASP tested practitioner votes against 6,639 classified real-world incidents, giving that evidence a quarter of the weight. Ranked by incidents alone, prompt injection drops out of the top 10, which OWASP attributes to heavy defensive effort keeping clean exploits out of public databases. Misinformation moved the other way: voters ranked it low, the incident record ranked it high, and it rose from ninth to seventh.
Read the ranking as a map of attention, not of your risk: output handling sits tenth, yet it is often what turns an injection into a leak.
Where guardrails sit
| Layer | What it catches | Typical techniques | Main limitation |
|---|---|---|---|
| Input screening | Abuse, known jailbreaks, personal data, off-topic requests | Small classifiers, redaction, input limits | Adaptive attackers evade it; benign text gets flagged |
| Capability limits | Injected instructions turning into actions | Least privilege, fixed plans, policy checks at each tool call | Narrows what the agent can do |
| Output validation | Malformed, out-of-policy, or unsupported answers | Schemas, business rules in code, groundedness judges | Judges are probabilistic; valid shape is not truth |
| Output handling | Leaks and injection into downstream systems | Context-aware encoding, no auto-loaded images, parameterized queries | Must be done for every destination |
| Human review | Irreversible or high-stakes actions | Approval screens that show the exact action | Slow, costly, and prone to fatigue |
| Adversarial testing | Gaps nobody has found yet | Adaptive red teaming, logged guardrail decisions | Can show a defense is broken, never that it is safe |
Why can’t a classifier stop prompt injection?
A model receives instructions and data as one stream of tokens. Chat roles and delimiters are cues it learned in training, not a boundary it must obey, so a retrieved email can still read as a command. That is why OWASP’s 2026 guidance says no dependable way to prevent injection exists today, and that defense has to live in the architecture.
The tempting fix is a detector that screens inputs for injection attempts. In October 2025, researchers from OpenAI, Anthropic, Google DeepMind, ETH Zurich, and others attacked 12 published defenses, four of them detectors, with methods tuned to each one. Most of those defenses had reported attack success near zero. Adaptive attacks pushed success above 90% for most of them, including against Meta’s PromptGuard and Google’s Model Armor detectors.
People did even better. A red-teaming competition with more than 500 participants and $20,000 in prizes succeeded in every case the authors evaluated. Many successful injections looked harmless, so a detector could not flag them without also flagging a lot of ordinary text.
Production systems are no exception. OWASP’s list recounts EchoLeak, a 2025 attack in which Aim Security showed that one crafted email could make Microsoft 365 Copilot leak organizational data, with no clicks from the user. The attack got past the injection classifier Microsoft had deployed and past a filter meant to strip links.
None of this makes detectors useless. They are cheap, they stop low-effort abuse at scale, and their flags are good telemetry. Treat them as a speed bump that raises attacker cost, never as the wall.
How do you contain an agent that might be fooled?
If injection cannot be reliably detected, the useful question becomes what an injected model is able to do. OWASP adopts Meta’s Agents Rule of Two as a floor. An agent that at once reads untrusted input, reaches sensitive data, and can change state or communicate externally is high-risk, and needs human approval for each action.
A June 2025 paper by researchers from IBM, Invariant Labs, ETH Zurich, Google, Microsoft, and others turns this thinking into six design patterns. Their shared rule: once an agent has read untrusted input, that input must have no route to a consequential action. Three of them fit many business agents:
- Action selector. The model only maps a request to actions from a fixed menu and never sees what those actions return. A support bot that can send an order link or point to account settings fits here.
- Plan, then execute. The model commits to its list of tool calls before touching untrusted data. Injected text can still change an email’s body, but it cannot add steps.
- Map-reduce. Each untrusted document goes to an isolated model call with no tools and a tightly constrained answer, such as yes or no. A poisoned file can then only lie about itself.
CaMeL (CApabilities for MachinE Learning), from researchers at Google, Google DeepMind, and ETH Zurich, goes further. A privileged model sees only the trusted request and writes a small program. A quarantined model with no tools turns untrusted text into values, and a custom interpreter tracks where every value came from, checking security policies before each tool call. On the AgentDojo benchmark, CaMeL completed 77% of tasks with provable security, against 84% for an undefended agent.
Its authors are candid about the gaps. An injection that merely distorts a summary, or slips a phishing link into an answer, never changes the data flow, so the policies cannot catch it. Policies also take effort to write and maintain, and frequent approval prompts wear users down.
The core idea needs no research interpreter, just ordinary application code that runs after the model proposes a tool call:
def authorize(call, session):
# Declared side effects and data scope.
tool = TOOL_REGISTRY[call.name]
if call.name not in session.approved_plan:
return deny(
"tool not in the plan fixed before "
"untrusted data was read")
# e.g., a refund over the limit, an unknown recipient.
ok = tool.business_rules_ok(
call.args, user=session.user)
if not ok:
return deny("arguments outside policy")
# All three risk factors present: a person decides.
risky = (
session.read_untrusted
and session.touched_private_data
and tool.external_effect
)
if risky:
return require_approval(render_exact(call))
return allow()
OWASP also recommends holding credentials and state-changing power in application code, not in the model. A model that never holds a token cannot be talked into leaking it.
Output guardrails: safe to use, and actually correct
Every model output is untrusted input to whatever consumes it next. OWASP’s output-handling advice reads like classic web security: encode output for the context it lands in, use parameterized queries, set a strict Content Security Policy, and strip terminal control characters. It adds a rule for chat windows and other renderers: do not auto-render Markdown images or link previews, because the address a renderer fetches can carry stolen data out in its query string.
Structure comes next. Check each response against a schema, in plain application code, before anything downstream uses it. OWASP prefers that deterministic check to a second model call, while noting its limit: a well-formed object can still carry a malicious query or a data-stealing email body.
Correctness needs more. On 14 February 2024, a British Columbia tribunal held Air Canada liable after its website chatbot told a grieving customer that a bereavement fare could be claimed after travel, contrary to the airline’s policy. The tribunal rejected the idea that the chatbot answered for itself, saw no difference between a chatbot and a static page, and awarded C$650.88 in damages. The ruling never says what technology ran the bot, but the principle covers any generated answer.
The practical controls: answer policy questions only from retrieved source text, require a citation, check amounts and eligibility in code, and hand off to a person when no source supports the answer. For checks that code cannot express, IBM’s Granite Guardian 4.1, released in April 2026 under the Apache 2.0 license, flags harmful content and jailbreak attempts, ungrounded answers in retrieval-augmented generation (RAG), and hallucinated function calls. It also accepts custom criteria written in plain language.
Its model card shows why judges are signals, not verdicts. It reports balanced accuracy, where 0.5 is chance and 1.0 is perfect, of 0.76 on groundedness benchmarks and 0.79 on function-call hallucinations. That is useful for flagging, sampling, and routing to review, not for silently blocking.
The guardrail budget: latency, cost, and false positives
Every check adds latency, compute, and a chance of refusing a legitimate user. Anthropic’s first-generation Constitutional Classifiers, which guard against help with chemical, biological, radiological, and nuclear (CBRN) weapons, added 23.7% to compute. They also raised refusals of harmless questions by 0.38%.
The successor, described on 9 January 2026, is a cascade. A cheap probe reads the model’s internal activations and screens all traffic, escalating suspicious exchanges to a stronger classifier that judges input and output together. Because a flag triggers a second look instead of a refusal, the first stage can tolerate more false positives. Over a month of Claude Sonnet 4.5 traffic, Anthropic reports a 0.05% refusal rate on harmless queries, an 87% drop, for roughly 1% extra compute.
You cannot probe a hosted model’s activations, but the cascade transfers. IBM makes the same split: it positions its main Guardian models for monitoring and spot-checks, and a 38-million-parameter model for hate, abuse, and profanity where latency budgets are strict. Run cheap deterministic and small-model checks on everything, and escalate only the ambiguous cases.
Streaming adds a subtler trade-off. As of October 2026, in NVIDIA’s open-source NeMo Guardrails toolkit, output checks on a streamed response run on chunks of 200 tokens by default. With the default setting, the user receives each chunk before its check runs, so blocked text may already be on screen. The stricter setting delays every chunk by the check time, so choose per surface.
Human review has a budget too. OWASP advises showing reviewers the exact action that will execute, not a summary, and warns that approval fatigue erodes judgment at volume. Reserve approvals for privileged, irreversible, or externally visible actions, or they become a rubber stamp.
A guardrail plan for launch
Practical defaults that hold up:
- Threat-model each feature. List what it reads, what it can touch, and what it can say that binds the company; that list decides the guardrails.
- Enforce limits in code. Use least-privilege tools, a plan fixed before untrusted data arrives, a policy check on every tool call, and no credentials in prompts.
- Treat every output as untrusted. Validate against schemas and business rules, encode for each destination, and turn off automatic image and link loading.
- Ground anything factual. Answer from sources, cite them, and escalate when the sources are silent.
- Cascade checks and measure them. Track false positives as closely as misses, and log every guardrail decision with the request it judged.
- Red-team adaptively. Give testers full knowledge of your defenses, and add each successful attack to the eval suite.
Common pitfalls: a vendor product treated as the whole security model, or a second LLM call as the only check on the first. Others are approvals on every action, so none gets real scrutiny, and blocked requests that dead-end instead of reaching a person.
Guardrails are what let a model be wrong sometimes while the product stays trustworthy. In the agents SurgeX Labs builds, the containment design — what a fooled agent could still reach — is settled before any classifier is chosen.
Sources
-
OWASP Top 10 for LLM Applications 2026 (opens in new tab) — OWASP GenAI Security Project, 2026 genai.owasp.org
-
The Attacker Moves Second: Stronger Adaptive Attacks Bypass Defenses against LLM Jailbreaks and Prompt Injections (opens in new tab) — OpenAI, Anthropic, Google DeepMind, ETH Zurich, and others (arXiv), 2025 arxiv.org
-
Design Patterns for Securing LLM Agents against Prompt Injections (opens in new tab) — IBM, Invariant Labs, ETH Zurich, Google, Microsoft, and others (arXiv), 2025 arxiv.org
-
Defeating Prompt Injections by Design (opens in new tab) — Google, Google DeepMind, and ETH Zurich (arXiv), 2025 arxiv.org
-
Next-generation Constitutional Classifiers: More efficient protection against universal jailbreaks (opens in new tab) — Anthropic, 2026 anthropic.com
-
Granite Guardian 4.1 8B (model card) (opens in new tab) — IBM (Hugging Face), 2026 huggingface.co
-
Output Rail Streaming Configuration (opens in new tab) — NVIDIA (NeMo Guardrails docs), 2026 docs.nvidia.com
-
Moffatt v. Air Canada, 2024 BCCRT 149 (opens in new tab) — Civil Resolution Tribunal of British Columbia, 2024 decisions.civilresolutionbc.ca
Where this shows up in our work
- Case study · client work Every sales tour, scored and coached — AI tour coaching: speech-to-text + LLM scoring
- Solution blueprint First drafts for every ticket — AI support copilot inside your helpdesk