Agent security guide

AI agent guardrails: what they catch, where they fail, and what goes behind them

AI agent guardrails are checks in the model's path, such as prompt-injection detectors, content safety filters, topic filters and PII redaction, that judge text going into and out of a model. They stop many noisy attacks and mistakes. But they are probabilistic, attackers adapt to them, and they can't see the record, the budget or who the agent acts for. Put deterministic controls behind them.

What AI agent guardrails are

AI agent guardrails are checks that sit in a model's path and judge text: what goes into the model, what comes out of it, and sometimes the tool calls it proposes. Most are classifiers, which are small models trained to label text, or rules such as word lists and regular expressions. They run inside an agent framework, in a model gateway or on the model provider's platform.

The word is used loosely. Vendors apply it to system prompts, content filters, PII (personally identifiable information) redaction and sometimes access control. This page uses the narrow meaning: probabilistic checks on content. That narrow meaning is what separates guardrails for AI agents from authorization, which decides whether an action may run.

Guardrails earn their place. They stop crude jailbreaks, keep a support assistant on topic, strip obvious personal data from answers and flag documents that seem to instruct the agent. OWASP's entry on LLM01:2025 Prompt Injection lists input and output filtering among its mitigations.

The same entry is plain about the limit. Because models are stochastic, "it is unclear if there are fool-proof methods of prevention for prompt injection." Treat AI agent guardrails as one layer of an AI agent security program, not as the boundary that keeps actions safe.

What AI agent guardrails catch, and what they miss

Each guardrail type answers one narrow question about text. The table shows what each is good at and where it goes blind.

Guardrail type Where it runs What it catches What it misses
Prompt-injection and jailbreak classifier User input Known patterns: role-play, "ignore previous instructions", attempts to change system rules New phrasings, attacks tuned against the classifier, payloads split across turns
Indirect (document) injection detector Retrieved documents, tool results, web pages Instructions addressed to the agent inside content Text it never sees: encoded, in unscanned attachments, or past its input limit; instructions that read like normal business requests
Content safety filter Prompts and responses Hate, violence, sexual and self-harm content, by category and threshold Polite requests with harmful effects, such as exporting every customer record
Topic filter (denied topics) Prompts and responses Off-topic or forbidden subjects, such as legal advice Business rules; any harmful request phrased inside an allowed topic
PII and secret detector Prompts, responses, tool results Card numbers, email addresses and API keys, by pattern or model Whether this recipient may see this value; values paraphrased or split
Output format and grounding check Model responses Malformed JSON; claims the source documents don't support Well-formed, grounded output that does the wrong thing
Tool-call judge Between the model and its tools Calls that are plainly off task, such as deleting files during a summary Amount limits, record ownership, budgets, who the agent acts for

Read down the last column. Most misses share one cause: a guardrail sees text, not facts. It can't tell whether an invoice belongs to the customer on the case, how much was refunded this week, or which person the agent is working for. Those facts live in systems of record and in the verified identity on the request. That is why decisions about actions belong to AI agent authorization, with guardrails in front.

Why guardrails are not a security boundary

Guardrails fall short as a boundary in three ways. None is a bug a vendor can patch. Each follows from what a guardrail is: a judge of text, working without facts, identity or credentials.

They are probabilistic, and attackers adapt

A classifier returns a score, and someone picks a threshold. Lower it and you block legitimate work; raise it and attacks pass. Prompt injection guardrails also face an attacker who can retry until something gets through. The OWASP LLM Prompt Injection Prevention Cheat Sheet lists bypasses such as scrambled words, encodings and repeated attempts, and says input screening "is not a security boundary."

Published results agree. In October 2025, Nasr, Carlini and co-authors reported adaptive attacks that bypassed 12 recent defenses against jailbreaks and prompt injection. Attack success rates were above 90% for most of them (The Attacker Moves Second). Simon Willison states the bar in security terms: "in web application security 95% is very much a failing grade" (Willison).

Model limits add gaps of their own. Meta's Llama Prompt Guard 2 model card states a 512-token context window, so long documents must be split or the tail goes unchecked. It also warns that "adversaries may develop sophisticated attacks specifically to bypass detection."

They can't see the facts that decide an action

A request for a $450 refund contains nothing a classifier can object to. Whether it should run depends on who owns the invoice, what was already refunded and who approved it. None of that is in the context window.

Vendors say so in their own documentation. Microsoft's page on Prompt Shields states that they "don't determine whether content is harmful, factually accurate, grounded in source material, compliant with policy, or aligned with the application's task." It adds that a "No prompt attack" result "doesn't establish that the request is benign."

They carry no identity and hold no credential

A guardrail doesn't know which agent sent the text or which person it acts for, so it can't apply different rules to each. It holds no key either. If the agent holds the API key, it can call the service whatever the guardrail concludes, and so can a developer's script. Detection is also not enforcement: Microsoft notes that the Content Safety API "doesn't itself block or route content." The application decides.

The UK National Cyber Security Centre (NCSC) said in December 2025 that prompt injection attacks "may never be totally mitigated" the way SQL injection can be. It urged teams to focus on reducing impact (NCSC).

LLM guardrails vs authorization

Guardrails and authorization answer different questions. Compare them by what they need and how they fail.

LLM guardrails Authorization
Question Does this text look malicious, harmful or off-limits? May this agent, for this person, run this operation on this record now?
Inputs Text in the model's context Verified identity, operation, parsed arguments, the record read from its system, budget counters, approvals
Output A score compared with a threshold Allow, deny or hold, from written rules
Can attacker text change the outcome? Yes: it reads attacker-supplied text Only through arguments, which are parsed as data and checked against facts
Where it runs Model path: framework, model gateway or provider An enforcement point in front of the service that holds the credential
How you test it Detection rates over a test set Example calls that must be allowed or denied
Typical failure A missed attack or a blocked legitimate request A rule written too broadly or too narrowly, visible in review

Here is an example from Northwind, a simulated company used in AgentFort's lab demos. Northwind's invoice reconciler agent asks to refund $4,500 on an invoice. No guardrail fires: there is no jailbreak phrasing, no personal data and nothing off topic. The authorization layer reads the invoice and the week's refunds, and blocks the call, because finance allows at most $2,000 per invoice per week. A $450 refund on the same invoice is held for a finance approver instead.

The guardrail had nothing to judge. The rule had everything it needed. Spending limits for AI agents covers how to set budgets like this one.

How to layer guardrails with deterministic controls

Layer controls so that each one covers a gap the previous one leaves. A practical order for an agent that reads outside content and calls tools:

  1. Decode, then inspect inbound content. Decode HTML entities, percent-encoding and base64 before any detector runs. Hold documents that seem to instruct the agent. See AI agent data loss prevention.
  2. Run guardrails in the model path. Use them to filter noise, keep the agent on task and catch harmful output.
  3. Constrain the agent's design. In June 2025, 14 researchers published six design patterns, such as plan-then-execute and dual LLM. Their principle: once an agent has read untrusted input, it "must be constrained so that it is impossible for that input to trigger any consequential actions" (Beurer-Kellner et al.).
  4. Authorize every tool call outside the agent. Check the operation, arguments, record, acting-for and budget at a point that holds the credential.
  5. Apply data rules per destination. Secrets never go to a model provider or an outside address.
  6. Sandbox code the agent runs. See AI agent sandboxing.
  7. Require approval for high-impact actions from someone other than the requester. See human approval.
  8. Record every decision, including denials, as audit evidence.

One rule ties guardrails to the deterministic layers: a guardrail signal may tighten a decision, never loosen it.

# Illustrative pseudo-policy: the guardrail verdict is one input, never a grant
action: billing.createRefund
deny_when:
  - record.invoice.customer != context.case.customer
  - record.refunded_this_week + args.amount > 2000
hold_for_approval_when:
  - args.amount > 100
  - context.inbound_guardrail.injection_suspected == true   # raises scrutiny only
otherwise: allow_if_granted

How to evaluate a guardrail

Treat a guardrail like any detection product. Measure it on your own traffic, against attackers who adapt, and under failure.

Measure How to test Watch for
False positives Replay a week of real, benign traffic, including content that quotes attacks, such as security training notes Legitimate work blocked; teams then switch the guardrail off
False negatives on known attacks Run public red-team suites and your own past incidents Suites only test attacks that are already published
False negatives on adaptive attacks Let a red team iterate against the deployed guardrail while seeing its responses Near-zero miss rates that come only from static tests
Coverage Send encoded text, long documents, tool results and attachments Inputs the guardrail never inspects
Latency Measure added time at the 95th percentile on your traffic, across a whole multi-step task Per-call costs that add up across many tool results
Failure behavior Stop the guardrail service mid-task Agents that carry on unchecked
Evidence Read what it logs Raw prompts and personal data in logs, or no record of the verdict

Open-source scanners and red-team frameworks, listed in AI agent security tools, automate much of this in continuous integration (CI). Read their results with care. OWASP's cheat sheet notes that passing such a smoke test "does not show resistance to a persistent adversary." Tuning helps with false positives: Meta's model card says fine-tuning Prompt Guard on domain-specific prompts "improves accuracy and reduces false positives."

Checklist: guardrails for AI agents

  • Write down what each guardrail is for, and what it is not for.
  • Decode content before any classifier sees it.
  • Scan tool results and retrieved documents, not only user input.
  • Split long documents to fit the classifier's input limit, and scan every part.
  • Measure false positives on real traffic before you switch to blocking.
  • Red-team with adaptive attacks, not only static test suites.
  • Let guardrail signals tighten decisions, and never let them grant access.
  • Authorize every tool call that changes data or moves money outside the agent.
  • Keep service credentials at the enforcement point, not in the agent.
  • Run code the agent writes or downloads in a sandbox.
  • Decide whether each guardrail fails open or closed, and test that behavior.
  • Log each verdict next to the decision it affected.

How AgentFort handles this

AgentFort doesn't rely on a classifier alone. AgentFort Data Protection inspects every call through the gateway in both directions: prompts, files and tool results. It first decodes text hidden behind HTML entities, percent escapes or base64. Deterministic rules find secrets, sign-in codes and personal data in microseconds, and check card and bank numbers with their checksums. For meaning, a low-latency language classifier answers typed questions, such as whether a document is trying to instruct the agent, and sees only text with every value replaced. A document with a hidden instruction is held for review before the agent reads it. Behind that, AgentFort Access checks each call's identity, operation, arguments and the record it touches, denies by default, and enforces budgets and approvals. See AgentFort Data Protection, watch a demo or become a design partner.

Frequently asked questions

Can an LLM be used as a guardrail for another LLM?

Yes, and many products do this, often called LLM-as-judge. A judge model understands meaning better than pattern rules, at a cost in latency and money. But OWASP's prompt injection cheat sheet points out that a guardrail model is an LLM too, so prompt injection can work on it as well. Text written to fool the main model can be written to fool the judge. Give the judge narrow, typed questions, keep it away from tools and credentials, and never make its verdict the only check before a consequential action.

Should AI agent guardrails block or only log?

Start by logging, then block where you have measured. Run a new guardrail in a log-only or annotate mode on real traffic, review what it flags, and tune thresholds before you enforce. Microsoft's Prompt Shields documentation, for example, suggests switching from block to annotate mode to investigate false positives. Block early only for high-confidence detections on untrusted content, and prefer holding content for a person over silently dropping it.

Do I need guardrails if I already have authorization?

Usually, yes. Authorization decides whether an action may run; it doesn't judge what an agent says or reads. An agent with tight permissions can still give a customer harmful advice, repeat personal data in a reply, or follow a hidden instruction within the actions it is allowed. Guardrails reduce those risks and filter noisy attacks early, which also cuts the load on approvers. Keep both, with authorization as the control that holds when a guardrail misses.

Do prompt injection guardrails work in languages other than English?

Often less reliably. Microsoft says the Prompt Shields models are primarily trained and evaluated on English content, and that performance can vary for other languages. Meta's model card for Llama Prompt Guard 2 notes a larger performance gap between its 22M and 86M models on multilingual data. Test any guardrail with attacks and with ordinary content in every language your agents handle, and expect attackers to switch languages when that helps them.

What guardrails does a customer support agent need?

A typical set: an injection detector on tickets, emails and attachments before the agent reads them; a topic filter that keeps answers on support subjects; PII detection on replies; and a content safety filter on outbound messages. Behind them, put deterministic controls on the support tools: grants per operation, refund limits per invoice and period, approval above a threshold, and masking of fields such as government ID numbers in customer records.

Sources

See it on your own agents

Put AI agents to work without putting your business at risk.

A working session on your agents: where discovery, identity and enforcement sit in your environment, and the evidence they produce.