# AI Agent Guardrails: Limits That Hold in Production

> AI agent guardrails that hold in production: six layers from input checks to a kill switch, what guardrail libraries cover, and what your own code must enforce.

- Author: Naman Gundaniya (https://hellonaman.com)
- Published: 2026-11-24
- Updated: 2026-11-24
- Canonical URL: https://hellonaman.com/blog/ai-agent-guardrails

AI agent guardrails are limits enforced by code outside the model: checks on what goes in, least-privilege tools and credentials, caps on steps and spend, validation of what comes out, human approval for high-impact actions, and a kill switch. Guardrail libraries mostly cover the text going in and out. Permissions, budgets and approvals are still yours to build.

A system prompt that says "never delete customer data" is an instruction, not a guardrail. The model usually follows it. A guardrail is the thing that holds when the model does not, because of a hallucination, a confusing input or a deliberate attack. This post sets out the layers I put around agents on client projects, with the published guidance behind each one.

## What are AI agent guardrails?

AI agent guardrails are controls that constrain what an agent can read, do and spend, enforced by ordinary software so they do not depend on the model behaving. The clearest statement of why they matter is OWASP's entry on [Excessive Agency](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/) in its 2025 Top 10 for LLM applications. OWASP describes it as the vulnerability that enables damaging actions in response to unexpected, ambiguous or manipulated model output, and names three root causes:

- **Excessive functionality:** the agent has tools it does not need.
- **Excessive permissions:** those tools can do more in downstream systems than the task requires.
- **Excessive autonomy:** high-impact actions go ahead without independent checking or approval.

Notice that none of the three is about the wording of a prompt. Each one is a design decision about tools, credentials and workflow. That is where guardrails belong.

## Which guardrail layers does a production agent need?

A production agent needs six layers, each catching a failure the others cannot. No single layer is reliable alone, so the aim is that a bad action has to get past several independent checks.

![Flowchart of six guardrail layers around an agent run. A request enters layer 1, input checks, which screen user input and tool results. It passes to layer 2, permissions, where the agent has only the tools and credentials the task needs. The agent loop then runs inside layer 3, budget and step caps, which stop the run at a turn, token or time limit. Each proposed action meets layer 4, output validation, and then a decision: is the action high impact? If yes, it goes to layer 5, human approval; if no, it executes. Layer 6, logging and a kill switch, runs underneath all the others and can halt the agent at any point.](https://hellonaman.com/blog/ai-agent-guardrails/diagram.svg)

*Six layers. A bad action has to get past all of them.*

| Layer | What it stops | Where it is enforced |
| --- | --- | --- |
| 1. Input checks | Abuse, off-topic requests, injected instructions | Before the model, and on tool results |
| 2. Permissions | Actions the agent should never be able to take | Tool list, credentials, downstream systems |
| 3. Budget and step caps | Runaway loops and surprise bills | Agent runner and API gateway |
| 4. Output validation | Malformed or policy-breaking results | After the model, before anything is sent |
| 5. Approvals | Irreversible or costly mistakes | Workflow, with a person deciding |
| 6. Logging and kill switch | Slow detection, no way to stop | Infrastructure, outside the agent |

### Layer 1: input checks

Input checks screen what reaches the model. Anthropic's guidance on [mitigating jailbreaks and prompt injections](https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/mitigate-jailbreaks) separates two threats. In the first, the user is the adversary, and the suggested defence is a lightweight model that pre-screens input and returns a simple classification. In the second, the user is trusted but the agent reads third-party content such as emails, web pages or tool results that contain instructions. For that case the guidance is to deliver untrusted content only inside tool results, tell the model where the content came from, and screen tool outputs before the model acts on them. My post on [prompt injection](https://hellonaman.com/blog/prompt-injection-explained) goes deeper on this threat.

### Layer 2: permissions

Permissions decide what the agent is able to do at all, which makes this the layer that matters most. OWASP's mitigations for Excessive Agency are almost entirely here: limit the tools to the minimum necessary, avoid open-ended tools such as a general shell, grant each tool the minimum permissions in downstream systems, and run actions in the user's own security context. One line deserves to be on the wall: implement authorization in downstream systems "rather than relying on an LLM to decide" whether an action is allowed.

In practice that means a read-only database role for an agent that only answers questions, separate tools for reading and writing, and per-user credentials so the agent can never see more than the person it works for.

### Layer 3: budget and step caps

Budget and step caps stop an agent that is looping, whether from a bug or a confusing task. Agent runners ship with a turn limit for this reason. The OpenAI Agents SDK documentation on [running agents](https://openai.github.io/openai-agents-python/running_agents/) states that if the run exceeds the `max_turns` passed, it raises a `MaxTurnsExceeded` exception. Set that limit deliberately, add a token or cost ceiling per run and per user, and put a timeout on every tool call. I cover the per-user side in [how to cap LLM costs per user](https://hellonaman.com/blog/cap-llm-costs-per-user).

### Layer 4: output validation

Output validation checks what the model produced before anything acts on it. For tool calls, that means strict schemas plus business-rule validation in your own code, as described in my post on [tool calling](https://hellonaman.com/blog/tool-calling-explained). For text shown to users, it means checks for leaked personal data, out-of-policy content or claims the agent must not make. The MCP specification asks servers to [validate all tool inputs and sanitize tool outputs](https://modelcontextprotocol.io/specification/latest/server/tools), which is the same principle applied at the tool boundary.

### Layer 5: approvals

Approvals put a person in front of actions that are expensive, irreversible or visible to customers. OWASP lists human-in-the-loop control for high-impact actions among its mitigations, and the MCP specification says there should always be a human in the loop with the ability to deny tool invocations. The design problem is choosing which actions need it. Approve everything and people stop reading the prompts. My post on [human-in-the-loop approvals](https://hellonaman.com/blog/human-in-the-loop-ai-agents) covers how to tier actions by risk.

### Layer 6: logging and a kill switch

Logging and a kill switch limit the damage when the other layers fail. OWASP is explicit that logging, monitoring and rate limiting will not prevent Excessive Agency but can limit the level of damage. A kill switch is a way to stop the agent that does not involve the agent: a feature flag that disables tool execution, a revocable credential, or a queue you can pause. Test it before you need it.

## What do guardrail libraries actually cover?

Guardrail libraries mainly cover checks on text entering and leaving the model, and in some cases checks around individual tool calls. They are useful for layers 1 and 4. They do not grant or restrict permissions in your systems, and most do not manage budgets or approvals.

Two examples show the shape. NVIDIA's open-source [NeMo Guardrails](https://github.com/NVIDIA/NeMo-Guardrails) describes five types of rail: input rails on user input, dialog rails that influence how the model is prompted, retrieval rails on retrieved chunks, execution rails on the input and output of custom actions, and output rails on what the model generates. The OpenAI Agents SDK offers [input guardrails, output guardrails and tool guardrails](https://openai.github.io/openai-agents-python/guardrails/), each able to trip a wire that halts the run.

The documentation for those SDK guardrails is honest about limits, and the limits are instructive:

- Input guardrails run only for the first agent in a chain, and output guardrails only for the agent that produces the final output.
- Input guardrails run in parallel with the agent by default, so if one trips, the agent may already have used tokens or run tools. A blocking mode avoids that at the cost of latency.
- Tool guardrails apply to function tools. Hosted tools such as web search and code interpreter, and handoffs between agents, do not pass through that pipeline.

None of this is a criticism. It simply shows that a library's guardrails sit at particular points in the flow. Anything that happens elsewhere, such as a tool acting on stale permissions or a sub-agent receiving unchecked input, needs its own control.

## Which guardrails should you build first?

Build permissions and caps first, because they hold even when every classifier misses. If I had one day to make an existing agent safer, I would spend it in this order:

- List every tool and remove the ones the agent does not need.
- Replace shared or admin credentials with scoped ones, read-only wherever possible.
- Set a turn limit, a per-run cost ceiling and tool timeouts.
- Add an approval step for anything that sends, pays, deletes or publishes.
- Log every tool call with its arguments and result, and add a switch that disables tool execution.
- Then add input and output screening, tuned on real traffic.

Screening comes last, not because it is unimportant, but because classifiers are probabilistic and the first five steps are not.

## How do you know the guardrails hold?

You know guardrails hold by attacking them on purpose and by watching them in production. Anthropic's guidance recommends red-teaming your own agent before deployment with documents, emails and tool outputs that deliberately contain injection attempts, and analysing outputs continuously afterwards.

I treat guardrails like any other code path: each one gets a test that triggers it. Does the turn limit stop a loop? Does a refund above the threshold wait for approval? Does a poisoned support ticket fail to change the agent's behaviour? Does the kill switch stop a run that is already in progress? Record how often each guardrail fires in production too. A guardrail that never fires is either unnecessary or broken, and one that fires constantly is training people to ignore it.

## Work with me

I build agents with these limits designed in from the first day, and I harden existing agents that grew without them. See [AI agent development](https://hellonaman.com/services/ai-agent-development) and [workflow automation](https://hellonaman.com/services/workflow-automation), or browse [my work](https://hellonaman.com/work) and book a scoping call.

## FAQ

### Are guardrails the same as a system prompt?

No. A system prompt influences what the model tries to do, but nothing enforces it. A guardrail is enforced by code outside the model, such as a permission check, a schema validator or a spending cap, so it still applies when the model is wrong or has been manipulated.

### Do guardrails stop prompt injection?

They reduce the damage more than they prevent the attempt. Screening catches some injected instructions, but no classifier catches all of them. Least-privilege permissions and approvals are what keep a successful injection from turning into a harmful action.

### Do I need a guardrail library?

Not always. A library helps with input and output screening and saves time if you need many checks. Permissions, budgets, approvals and a kill switch are ordinary engineering that no library can do for you, because they live in your own systems.

### Do guardrails slow the agent down?

Some do. A blocking input check adds one fast model call before the agent starts, and approvals add human time by design. Permission checks, schema validation and caps cost almost nothing. Put the slow checks only where the risk justifies them.

## Sources

- [Excessive Agency (genai.owasp.org)](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/)
- [mitigating jailbreaks and prompt injections (platform.claude.com)](https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/mitigate-jailbreaks)
- [running agents (openai.github.io)](https://openai.github.io/openai-agents-python/running_agents/)
- [validate all tool inputs and sanitize tool outputs (modelcontextprotocol.io)](https://modelcontextprotocol.io/specification/latest/server/tools)
- [NeMo Guardrails (github.com)](https://github.com/NVIDIA/NeMo-Guardrails)
- [input guardrails, output guardrails and tool guardrails (openai.github.io)](https://openai.github.io/openai-agents-python/guardrails/)
