IamBishal
AI Engineering

Guardrails in Agentic AI: Why They Matter Once Agents Can Act

A system prompt is a request, not a control. Real guardrails live outside the model, and they are what let you grant autonomy at all.

Bishal Saha

14 min read

A system prompt is a request made to a probabilistic component. A guardrail is something the agent cannot talk its way past.
Bishal Saha

In July 2025, Jason Lemkin of SaaStr was testing Replit's AI agent when, during a code freeze, it deleted his production database. By Lemkin's account, the database held records for 1,206 executives and more than 1,196 companies. The agent then told him a rollback was impossible. That turned out to be wrong: the data was recovered. Replit's CEO, Amjad Masad, called the deletion "unacceptable and should never be possible". The fixes the company announced were structural rather than verbal: automatic separation of development and production databases, better checkpoint and restore, and a planning/chat-only mode. (The Register)

None of those fixes is a better prompt. Each one changes what the agent can reach or how far its mistakes spread. That difference, between asking an agent and constraining it, is the whole case for guardrails.

1. From saying to doing

For a chat-style LLM application, the worst thing the model can do is say something. A wrong answer, a hallucinated citation, an embarrassing reply in a support chat. Those failures are real, but a human usually reads the output before anything happens, and that reader is the safety net.

An agent removes the reader. It plans, calls tools, reads the results and calls more tools. The output is no longer text someone reviews. It is a refund issued, a ticket closed, a row deleted, an email sent to a customer. The worst case changes from a bad answer to a bad action, and many actions can't be taken back.

OWASP's Top 10 for LLM Applications has carried an entry called Excessive Agency for a while, and in the 2026 edition it rose from sixth place to third. The 2026 announcement quotes Michael Bargury calling it "the risk where expert judgment and the record agree most clearly". OWASP now also publishes a separate Top 10 for Agentic Applications, released in December 2025.

The 2025 Excessive Agency entry names three root causes, and they map directly onto design decisions: excessive functionality, excessive permissions and excessive autonomy. Too many tools, tools that can do too much, and too little checking before they run.

This is why I treat guardrails as a ship blocker for agents rather than a hardening task for later. A chatbot without guardrails is a quality problem. An agent without them is a system that can take consequential actions nobody has bounded.

2. A system prompt is a request, not a control

The first guardrail many agent designs reach for is a paragraph in the system prompt: never delete data, never touch production, always ask before sending email. It feels like a control: it is written in the imperative and usually works in testing.

It is not a control. It is a request made to a probabilistic component, and the request shares a channel with everything else the model reads.

That second point matters more than the first. In 2023, Greshake and colleagues showed that an attacker doesn't need access to the model at all. In this indirect prompt injection, they plant instructions in content the application retrieves (a web page, a document, an email), and the model treats them as instructions, just as it would a user typing them directly. The paper demonstrated data theft and control over API calls this way.

The UK's National Cyber Security Centre puts the underlying problem bluntly: inside an LLM there is no distinction between data and instructions, "there is only ever 'next token'", which makes the model an "inherently confusable deputy". OWASP's 2025 guidance on prompt injection says it is unclear whether fool-proof prevention exists, and a later NCSC warning says such attacks "may never be totally mitigated".

So an agent that reads untrusted content, as most useful agents do, has a system prompt that any of that content can argue with. And even without an attacker, the model can simply get it wrong. A freeze that exists only as words in the context is a freeze the agent can misread, forget halfway through a long task, or reason its way around.

System prompts can still lower the rate of bad decisions. But they lower a rate. A guardrail is something the agent cannot talk its way past, however confident or confused it is. That means it has to be enforced by deterministic code the model doesn't control.

3. Where agent guardrails actually live

If the model can't be the enforcement point, the enforcement has to sit around it. I find it useful to picture the agent's loop as an untrusted client of your own systems, wrapped in layers that each enforce something the model has no say over.

flowchart LR
    subgraph A[Agent loop]
        P[LLM plans next step] --> TC[Proposes tool call]
        R[Reads result] --> P
    end

    U[User] -->|delegates| ID["Identity & scoped token"]
    ID -.->|"attached by code, never in context"| T

    TC --> PEP{Tool-call policy<br/>allowlist · arguments · egress · authZ}
    B[Runtime budgets<br/>steps · spend · rate · time] -.limits.-> A
    PEP -->|low risk| T[Tools & APIs<br/>authorise again downstream]
    PEP -->|high impact| H[Human approval]
    H -->|approved| T
    PEP -->|denied| X[Blocked call]:::warn
    PEP -.every decision.-> L[(Audit log)]
    T -.->|"result, untrusted"| R
    T -.-> L
    H -.decision.-> L

The shape matters more than the boxes. Every action goes through one checkpoint that sits outside the model, and the systems behind that checkpoint still check authorisation themselves. OWASP's 2025 guidance calls this complete mediation: implement authorisation in downstream systems rather than relying on the LLM to decide whether an action is allowed.

The diagram leaves out classifier rails and environment isolation, both in the table. Each layer earns its place by catching something the others miss:

LayerWhat it catchesWhat it missesWhat it costs
Identity and scoped credentialsActions outside what this user, for this task, is allowed to doMisuse of permissions the agent legitimately holdsDelegation plumbing; scopes have to be designed per tool
Tool-call policyDisallowed tools, out-of-range arguments, calls to unapproved destinations, calls that break business rulesHarmful sequences of individually valid callsPolicy has to be written and kept in sync with the tools
Runtime budgetsLoops, runaway spend, bulk actions at machine speedA single bad action that fits inside the budgetLegitimate long tasks hit limits and need a resume path
Human approvalHigh-impact or irreversible actionsActions the policy misroutes as low risk; anything a tired approver clicks throughLatency, reviewer time, approval fatigue
Classifier railsUnsafe content, obvious jailbreaks, some suspicious tool callsNovel or well-crafted injections; they are probabilistic tooExtra model calls, false positives
Environment isolationDamage beyond a sandbox or a non-production copyAnything reachable from inside the environmentSeparate environments, data copies and a promotion step
Audit and observabilityAnomalies, through alerts that can halt a runPrevention: at best it limits damage, it doesn't stop the first bad actionStorage, plus someone who reads the logs

Identity is where I start. In IAM terms an agent is a new kind of principal, and the tempting shortcut is a service account that can do everything any user might ever need. The better pattern is delegation: the agent acts on behalf of a specific user, with a token scoped to that user's permissions and this task's tools, and short-lived.

The token stays in the tool layer: code attaches it when a call executes, so it never enters the model's context, where injected text could ask for it. Agents with no user present, such as scheduled or event-driven jobs, need a workload identity instead, scoped to the one task rather than borrowed from an admin.

The Model Context Protocol's authorisation spec covers part of this. A protected MCP server acts as an OAuth 2.1 resource server; it must reject tokens that weren't issued for it as the audience, and it must not pass the client's token through to upstream APIs. Per-user permissions remain your design, and authorisation is optional in MCP, so none of this is on by default. The passthrough trap is the subject of MCP server authorization and the confused deputy.

Policy is where most of the work lands. A useful tool-call policy checks more than the tool name. It checks the arguments against limits (an amount ceiling, a single record rather than a wildcard), the target against the user's own scope, and the destination of anything that leaves your systems. The destination check limits exfiltration: an agent whose outbound email, HTTP and webhook calls only reach an allowlist has a much smaller exfiltration path. An allowlist narrows that path without closing it, since an approved mailbox or a URL an attacker can influence can still carry data.

Classifier rails are a layer, not the guardrail. Tools such as NVIDIA's NeMo Guardrails go further than content moderation, with execution rails that validate tool calls, their arguments and their results. That is useful. But when the check is itself a model, it is a probabilistic judgement, and the Llama Guard 3 model card warns that Meta's classifier may itself be open to adversarial and prompt injection attacks. Willison puts it well: for security, a filter that catches 95% of attacks is "very much a failing grade". Use classifiers to cut noise and catch the obvious cases, never as the reason an action is allowed.

4. Guardrails are what buy autonomy

An agent with no guardrails can't safely be left alone, so in practice it isn't. Every meaningful action goes to a human, the "agent" becomes an elaborate suggestion engine, and the productivity gains are hard to find. The guardrails are what let you remove the human from the routine path, because they bound what can go wrong when the human isn't there.

The useful question isn't "should this agent be autonomous?" but "for which actions, under which limits?" Two properties of an action decide most of it:

  • Reversibility. Can the effect be undone cleanly, by you, without asking anyone? A draft, a label, a staged change: yes. A sent email or a payment: no. A dropped table is reversible only if a restore exists and has been tested, which is a property of your system, not of the action.
  • Blast radius. If the action is wrong, how much does it touch? One record or every record. One customer or all of them.

Reversible and small: let the agent act, log it, and review in aggregate. Reversible and large: run it under a budget and checkpoint first. Irreversible and small: policy checks, and approval if the stakes justify the friction. Irreversible and large: a human approves, every time, with the actual arguments shown rather than a summary the model wrote.

The less reversible the action and the wider its reach, the more guardrails it needs before the agent may act alone.

A support agent, for instance, might tag tickets and draft replies freely, issue refunds under a small cap after a policy check, and send a bulk email to customers only after someone approves the list and the text.

Notice how much of Replit's announced response fits this grid. Separating development and production databases shrinks the blast radius of a mistake. Better checkpoints make more actions reversible. A planning-only mode sets autonomy to zero. None of these makes the agent smarter. All of them make it safer to let the agent act.

Willison's lethal trifecta is a good design-time check here. An agent that has access to private data, is exposed to untrusted content and can communicate externally can be steered into leaking data, whatever its prompt says. If your design has all three, remove one by architecture. Keep private data away from agents that read untrusted content. Quarantine that content so the model reading it has no tools, as in Willison's dual LLM pattern or CaMeL, described in the next section; both cost complexity or capability. Or close the external channel with an egress allowlist. A sentence in the system prompt won't do it.

5. What guardrails cost to run

Guardrails aren't free, and pretending otherwise is how teams end up switching them off.

Every layer adds latency, from a cheap policy check to a classifier call to an approval that can take hours. False positives are a real operational cost: a policy that blocks a legitimate refund generates a support ticket, and a run of them generates pressure to loosen the policy. Approval fatigue is the quietest failure of all. After enough routine approvals, the next one can get clicked through without being read, and then you have a guardrail on paper only.

Designs that are secure from the start cost something in capability, too. CaMeL, a research design from Debenedetti and colleagues, separates the agent's control flow from the untrusted data it reads, and it enforces policy on tool calls outside the model. On the AgentDojo benchmark, under the paper's threat model, it completed 77% of tasks with provable security, against 84% for an undefended agent. One benchmark doesn't set a general price, and your tasks may lose more or less. What the result does show is that the trade is measurable, so it can be made deliberately rather than discovered in production.

So guardrails need owners. Someone tunes the policy, watches the false-positive rate, adjusts which actions need approval as trust builds, and reads the audit log. A guardrail with no owner decays into either friction or decoration.

6. What I'd require before an agent ships

This is the bar I'd hold an agent to before signing it off for production.

  • A named identity. Whose permissions does the agent act with, how narrow is the token, and how long does it live? A shared service account with broad access stops the review.
  • A justified tool list. OWASP's first mitigation for excessive agency is to minimise the tools and what they can do, and open-ended tools like a shell need a strong argument. Each tool's policy, egress included, is enforced outside the model, and the downstream system checks authorisation on its own.
  • Classified actions. Every action is placed on the reversibility and blast-radius grid, and the high-impact ones go through an approval that shows the real arguments. The MCP spec asks clients to show tool inputs and confirm sensitive operations, and its 2026-07-28 revision added multi-round-trip requests so a server can pause mid-call for that confirmation.
  • Hard budgets on steps, spend and rate, so a loop fails fast instead of failing big. Setting them is the subject of Your AI agent needs a circuit breaker.
  • An audit trail good enough to reconstruct what the agent did and why, and a named person who reads it.
  • A way to stop it. A kill switch that halts runs in flight, and a restore that has actually been tested for every action the grid treats as reversible.
  • Evidence the guardrails hold. Injection and misuse cases run against the real policy layer, kept as regression tests, so a policy edit that reopens a hole fails a build instead of reaching production.

Finally, I'd ask the team one question: if the system prompt were deleted tomorrow, what would still stop the worst action? If the answer is "nothing", the agent isn't ready.

View All Articles

Bishal SahaLet's build together

Have a system to design, or an AI feature to get right?

Tell me about the problem. You'll get a clear, honest view of the best way forward.

  • Reply within 24 hoursOn business days, with my honest view and a next step.
  • Accepting select engagementsArchitecture, AI features and full builds.
  • Remote, worldwideWorking with startups, SMEs and enterprises.