Blank white background with no objects or features visible.

TrueForgeのご紹介:オープンソースでベンダーフリーなエージェントハーネス。コストを50%削減します。今すぐ試す→

AI Agent Guardrails: Inspecting Every Tool Call and Model Hop

By アシシュ・ドゥベイ

Published: August 25, 2026

⚡ TL;DR

AI agent guardrails inspect what flows through an agent — the prompts, the model outputs, and every MCP tool call — and block or rewrite anything unsafe before it acts. Identity decides whether a call is allowed; guardrails decide what the call is allowed to contain. On TrueFoundry, guardrails run at the AI Gateway on four hooks (LLM input, LLM output, MCP pre-tool, MCP post-tool), so the same policy covers every agent with no per-agent code. This guide walks through where guardrails run, which risks they stop, and how to roll them out.

A chatbot with a bad response embarrasses you. An agent with a bad response acts on it. That single difference is why AI agent guardrails have become a production requirement rather than a nice-to-have. The moment a model can call tools — query a database, hit an internal API, run code, post to Slack — a hallucinated argument or an injected instruction stops being a wording problem and becomes an action your systems execute.

The 2025 Comet browser incident is the canonical example: a webpage carried hidden instructions written for the agent summarizing it, and the agent followed them. That is indirect prompt injection — untrusted content turning into unauthorized actions. No amount of identity or access control stops it, because the credential presented was perfectly valid. What stops it is a content check at each hop. This guide covers what agent guardrails are, where they run on the AI Gateway, which risks each one addresses, and how to enforce them without rewriting a single agent.

What Are AI Agent Guardrails?

AI agent guardrails are content-inspection controls that examine the actual payload of every agent interaction — the user prompt, the model's response, and the arguments and results of each tool call — and take action (allow, block, or rewrite) based on policy.

It helps to separate two questions every governed agent call has to answer:

  • Whether the call is allowed — handled by identity and access control (which agent is this, what is it permitted to do).
  • What the call contains — handled by guardrails (is there an injection in this tool result, a secret in this output, a DROP TABLE in these arguments).

Access control is the bouncer at the door; guardrails are the metal detector. You need both. An agent can be fully authorized to call your Postgres MCP server and still be tricked into sending a destructive query — access said yes, and only a guardrail on the tool arguments catches what the query actually is.

Why agents raise the stakes

Guardrails aren't new to LLM apps, but agents change the problem in three concrete ways:

  • Untrusted content flows in continuously. Every tool result — a web page, a support ticket, a database row — re-enters the model's context on the next turn. Any of it can carry an injection, so inputs need checking even when the user is trusted.
  • Outputs become actions. A hallucinated shell command or an over-broad SQL statement doesn't just read badly; it runs. Tool arguments need checking before the tool executes.
  • Chains multiply exposure. A five-tool chain is five chances to leak a secret or exfiltrate PII. Effective guardrails run on every tool call separately, so each hop gets its own checks.

Where AI Agent Guardrails Run: The Four Hooks

On TrueFoundry, guardrails are enforced at the gateway on the agentic call path — the chain of user → app → agent → sub-agent → MCP tool calls. Every governed hop passes an interception point with a before and after hook.

How TrueFoundry runs guardrails on each hook of the agentic call path
Product screenshot — TrueFoundry docs: guardrails execute on LLM input/output and MCP pre/post-tool hooks.
Surface Hook Runs Typical checks for agents
LLM call Input Before the prompt reaches the model PII masking, prompt-injection detection (incl. injected tool results), content moderation
LLM call Output After the model responds Secrets detection, unsafe-code detection, content filtering
MCP tool call Pre-tool Before the tool executes SQL sanitizer, code-safety linter, parameter validation, Cedar/OPA policy checks
MCP tool call Post-tool After the tool returns Secrets and PII redaction from results, code safety on returned content

The ordering matters for cost and blast radius. A pre-tool failure means the tool never executes — the cheapest possible failure. An LLM input failure cancels the in-flight model request before you pay for it. Because every hop is checked independently, a compromised tool result on hop three is caught on hop three, not after it has already fanned out into three more calls.

Matching Risks to Guardrails

The value of running guardrails at the MCP Gateway is that each real agent risk maps to a specific, built-in control. TrueFoundry's built-in guardrails run on TrueFoundry-managed infrastructure — no third-party API keys to provision.

Risk Guardrail Hook
Indirect prompt injection via tool results or documents Prompt injection detection (Azure Prompt Shield under the hood) LLM input
PII reaching an external model or leaking in results PII / PHI detection and redaction (Azure AI Language) LLM input, post-tool
Credentials leaking through model output or tool results Secrets detection LLM output, post-tool
Destructive database operations (DROP, DELETE without WHERE) SQL sanitizer Pre-tool
Dangerous shell commands or unsafe code Code safety linter Pre-tool, LLM output
Tool calls that violate fine-grained policy Cedar / OPA policy guardrails Pre-tool
Requests missing required context (environment, cost center) Metadata validation LLM input

Beyond the built-ins, the gateway plugs into external providers — Palo Alto Prisma AIRS, CrowdStrike AIDR, Cisco AI Defense, AWS Bedrock Guardrails, Google Model Armor, NVIDIA NeMo Guardrails, Guardrails AI, and more — and supports fully custom guardrails when you need logic specific to your domain.

The prompt-injection guardrail is the one built specifically for the agent problem: it analyzes the user prompt and any document or context content separately, so an injection hidden inside a returned web page or ticket is caught even when the user's own message is clean.

Ship agents that can't act on a bad instruction.

TrueFoundry enforces prompt-injection, PII, secrets, and unsafe-tool-call checks on every agent hop — inside your own VPC.

How to Implement Guardrails for AI Agents

Applying guardrails to agent traffic is a three-step flow, and crucially none of it lives in your agent code.

Step 1 — Register the guardrails

In AI Gateway → Guardrails, create a guardrails group and add the integrations you need — built-in, external provider, or custom. A group is also the unit of access control: a Manager can add, edit, and delete guardrails; a User can only apply them. A common pattern is one org-wide group owned by the platform team, plus per-team groups for product-specific checks.

Registering a guardrails group in the TrueFoundry AI Gateway
Product screenshot — TrueFoundry docs: AI Gateway → Guardrails.

Step 2 — Create policies that attach guardrails by target

In AI Gateway → Policies → Guardrails, create rules that decide when each guardrail runs. This is what makes the model scale to fleets of agents: rules are keyed on the target (the models, MCP servers, and even specific tools being called) and the subject (users, teams, or virtual accounts). Because a rule covers every caller of a given MCP server or model, it protects every agent that touches that target — with no per-agent setup.

Each rule combines:

  • Targets — models (IN / NOT IN) and MCP servers, optionally narrowed to specific tools (e.g. only the run_query tool of a database server).
  • Subjects — IN / NOT IN filters on users, teams, or virtual accounts.
  • Metadata — match on X-TFY-METADATA key-values, so a rule can apply only to environment: production.
  • Hooks — attach the registered guardrails to LLM Input, LLM Output, MCP Tool Pre-Invoke, or Post-Invoke.

Configuring a guardrail policy rule by target, subject, and hook

Product screenshot — TrueFoundry docs: guardrail policy rule editor.

All matching rules are evaluated and their guardrails are merged per hook. If Rule A applies PII detection on LLM Input and Rule B applies prompt-injection detection on LLM Input, both run. A rule with no target or subject conditions becomes a baseline that applies to all traffic — useful for a company-wide prompt-injection check on top of everything else.

For quick tests or one-off calls, you can also pass guardrails per request with the X-TFY-GUARDRAILS header, which bypasses policies entirely:

curl https://<your-gateway>/api/llm/chat/completions \

  -H "Authorization: Bearer $TFY_API_KEY" \

  -H 'X-TFY-METADATA: {"environment":"production","agent":"research-agent"}' \

  -H 'X-TFY-GUARDRAILS: {"llm_input":["global/prompt-injection","global/pii-detection"]}' \

  -H "Content-Type: application/json" \

  -d '{

        "model": "openai-main/gpt-4o",

        "messages": [{"role":"user","content":"Summarize ticket #4521 and email the customer"}]

      }'

Step 3 — Verify in traces

Every request is traced with the guardrails that ran and their verdicts, so you can confirm coverage before you trust it. This is also where you tune false positives, which matter more for agents than for chatbots: a blocked hop can fail an entire chain.

Verifying which guardrails ran on a request in the trace view

Product screenshot — TrueFoundry docs: guardrail results in a request trace.

Before shipping, use the Playground to fire test prompts and tool calls against all four hooks and watch what gets caught.

Testing guardrails on each hook in the AI Gateway Playground

Product screenshot — TrueFoundry docs: AI Gateway Playground.

Enforcement Modes: Validate, Mutate, and How Hard to Block

Two settings control how each guardrail behaves.

Operation mode:

  • Validate — inspect and block (e.g. prompt injection detection, which only detects and blocks).
  • Mutate — rewrite the content and optionally block (e.g. PII detection redacting an email before the prompt reaches the model).

Enforcement strategy:

  • Enforce — block on a violation and if the guardrail itself errors. Use for strict-compliance checks like PII.
  • Enforce But Ignore On Error — block on a violation, but let traffic through if the guardrail provider has an outage. The pragmatic default for most agent traffic.
  • Audit — log only, block nothing.

For custom logic, you deploy a guardrail as an HTTP service and the gateway reads its response contract: an HTTP 2xx means the guardrail ran, and the JSON body carries the outcome — verdict: false to deny, or a mutated result body to rewrite:

Try now.

One gateway for all your models, MCP servers, and agents.
No credit card needed.

Start free
Table of Contents

One Gateway for Every LLM, Agent and MCP Server

Book a 30-min with our AI expert

Book a Demo

The fastest way to build, govern and scale your AI

Book Demo
Summarize with
ChatGPT logo by OpenAI
Perplexity AI logo
Blurry red snowflake on white background, symmetrical frosty design with soft edges and abstract shape.

Discover More

No items found.
August 25, 2026
|
5 min read

AI Agent Guardrails: Inspecting Every Tool Call and Model Hop

No items found.
August 25, 2026
|
5 min read

Agent Interoperability: One Control Plane for Any Framework

No items found.
August 25, 2026
|
5 min read

Claude Skills: What They Are and How to Govern Them at Scale

No items found.
August 25, 2026
|
5 min read

AI Agent Identity: Giving Every Agent a Non-Human Identity

No items found.
No items found.

Recent Blogs

Black left pointing arrow symbol on white background, directional indicator.
Black left pointing arrow symbol on white background, directional indicator.
Take a quick product tour
Start Product Tour
Product Tour