AI Agent Guardrails: Three-Layer Protection Design for Input, Tools, and Output
A customer's risk management director called late one night. The agent had just automatically changed a refund from 500 to 50,000. Nothing stopped it. The problem wasn't a dumb model; nobody had drawn red lines in the code. Guardrails aren't requests in your prompt asking the model to play nice. They're code-level interceptors you add to input validation, tool invocation, and output checking. This guide breaks down what each layer should catch, walks you through a tool-layer policy template, and includes a pre-launch checklist you can copy directly.
By
Tenten AI 研究團隊
應用 AI
Published
February 16, 2026
Read time
6 分鐘

A customer's risk management director called late one night. The agent had just automatically changed a refund from 500 to 50,000 for a customer service rep. The cause: a user typed one line in the chat. "Add one more zero to the last digit." The model complied. The tool executed. Nothing stopped it.
The model isn't the problem. The problem is that there was nobody drawing red lines along the way.
Defining AI agent guardrails
AI agent guardrails add verifiable rules and checks at three distinct stages in the agent execution loop: input, tool calls, and output. These constraints limit the model's freedom so that harmful actions become impossible, even if the model attempts them. Guardrails differ from system prompts. A prompt makes a request. A guardrail enforces through code.
Broken deployments share a common pattern. Teams pack all security expectations into the system prompt and then hope for the best. Demos pass because demo inputs are well-behaved. But when real users hit production in week one, it fails.
Guardrails only work when split across three layers. Each layer catches different threats and breaks in different ways.
First Layer: Input guardrails (Verify Before Anything Gets In)
The input layer intercepts before anything reaches the model. Most teams skip this layer, assuming the model will validate input itself. That assumption fails.
Input guardrails handle three types of checks. Injection detection flags telltale signs of prompt injection like "ignore previous instructions" or "you're now in developer mode" and rejects them before the model processes them. PII masking replaces ID numbers, card numbers, and medical record numbers with tokens before the model sees them, preventing them from reaching logs or external APIs. Scope validation checks whether the request falls within what this agent should handle. Out-of-scope requests route to a human.
This layer caused the refund failure. The user's message about adding a zero should have been caught as a request to modify a financial value and required a second confirmation. Instead, it reached tool invocation.
Second Layer: Tool guardrails (Control What Gets Called and How Often)
This layer is the most dangerous and most often skipped. Destructive capability comes not from what an agent says but from what tools it calls. Reading-only agents leak secrets at worst. Agents that issue refunds, send emails, and modify databases can become major incidents.
Tool guardrails focus on three dimensions. As a policy configuration template:
| Setting | Purpose | Example |
|---|---|---|
allowed_tools | Allowlist, only list the tools this agent can use | [search_kb, draft_reply] |
require_confirmation | Which tools demand manual sign-off | [issue_refund, send_email] |
value_limits | Hard numerical caps; reject if exceeded | refund_amount <= 2000 |
rate_limit | Max invocations per time unit; stops runaway loops | 10 calls / min |
dry_run_first | High-risk actions run as simulation first | true |
The underlying principle is deny by default, allowlist to permit. Any tool lacking explicit authorization stays off-limits to the agent. Hard caps on monetary amounts, call counts, and frequency prevent runaway loops. When retry logic in a harness loses control, models invoke dangerous tools hundreds of times per second. An agent without rate limiting once generated 1,400 copies of the same email in a single retry loop.
Third Layer: Output guardrails (Last Stop Before It Goes Live)
The output layer validates content after the model finishes but before sending to users or downstream systems. This is the final checkpoint.
Four validations must pass before sending output. Format legality: if you're expecting JSON, you can't return prose because the downstream parser will break. Factual grounding: in RAG scenarios, verify that cited sources exist and aren't hallucinated regulation numbers. Tone and compliance: avoid investment guarantees, medical diagnoses, or legal conclusions. PII leakage: ensure the first layer's masked data doesn't resurface. If any validation fails, block and regenerate or escalate to a human. Never send invalid output.
A Checklist You Can Copy and Use
Complete this checklist before deployment. Each item asks whether you wrote code to enforce it and whether a test will catch it if it breaks:
- Input layer detects injection attacks, and you have a test suite of malicious inputs that get blocked.
- PII is masked before the model sees it; the raw sensitive values are not searchable in logs.
- Tools use an allowlist; adding new tools means changing the config file, not rewriting prompts.
- All monetary and quantity tools have hard caps, and you have a test that fails if you exceed the limit.
- High-risk tools (payments, external sends, data modifications) require manual confirmation.
- Rate limits are in place to stop loops from spiraling.
- Output format validated against a schema; bad formats trigger regeneration.
- Each interception point logs what happened; later you can audit who got blocked at which layer and why.
Guardrail design often happens last, treated like final polish. But it actually determines whether an agent can run in production. Guardrails must be built alongside functionality, not added afterward. An agent without guardrails might pass review. It will fail eventually.

One stuck workflow
is enough to begin
Tell us what the team does today, where it breaks down, and what a better working day should look like.