1
Register guardrails
In AI Gateway → Guardrails, create a guardrails group and add the guardrail integrations you want to use — TrueFoundry guardrails, external providers, or your own custom guardrails. See the Getting Started guide for a walkthrough.
2
Configure policies
In AI Gateway → Policies → Guardrails, create policy rules that decide when to apply which guardrails — based on the model or MCP server being called, the user or team making the request, and request metadata — and on which hooks they run (LLM input/output, MCP tool pre/post invoke).
Registering a guardrail does not apply it to any traffic by itself. Guardrail policies are what attach registered guardrails to requests. The only exception is passing guardrails per-request via the
X-TFY-GUARDRAILS header, which bypasses policies entirely.Create a Guardrail Policy
Navigate to AI Gateway → Policies → Guardrails and click Add Rule. Each rule has a unique Rule ID and the following sections:When Request Goes To (Targets)
Define which traffic the rule applies to. Click Add Targets to add conditions on:- Models — Select one or more models with an
INorNOT INcondition. If no model condition is set, the rule matches requests to any model. - MCP Servers — Select one or more MCP servers, and optionally narrow down to specific tools within each server (for example, only the
ask_questiontool of a server).
From Subjects
Specify who the rule applies to. Click Add Filters to addIN / NOT IN conditions on users, teams, or virtual accounts. For example, apply a rule to team:data-science but exclude user:admin@company.com. If no subject filter is set, the rule applies to all callers.
With Metadata
Match requests based on metadata key-value pairs sent in theX-TFY-METADATA header. For example, a rule with metadata environment: production only applies to requests carrying X-TFY-METADATA: {"environment": "production"}.
Apply on Hooks
Attach your registered guardrails to one or more hooks. Click Add Hook, pick the hook, and select the guardrail integrations to run on it:
You can attach multiple guardrails to the same hook — all of them run for matching requests.
Set a Custom Error Message
By default, when a guardrail blocks a request, the client receives the provider-specific failure detail. You can override this with a Custom Error Message per rule — useful for showing end users a friendly, actionable message instead of raw guardrail output. The message supports two placeholders:
For example:

Custom Error Message field in the guardrail rule editor — toggle advanced fields to show it
{{guardrail_message}} continue to work unchanged.
How Policies Are Evaluated
- All rules are evaluated for every request. The guardrails from all matching rules are combined (union) and applied together.
- If multiple rules match, their guardrails are merged per hook — for example, if Rule A applies PII detection on LLM Input and Rule B applies prompt injection detection on LLM Input, both guardrails run.
- A rule with no target or subject conditions matches all requests. Use this for baseline guardrails that should apply universally alongside any other matching rules.
- Omitted conditions are not used for filtering — if a rule has no model condition, it matches any model.
YAML Configuration
Guardrail policies can also be managed as YAML — useful for reviewing the full policy set or managing it through automation. The configuration contains an array of rules, each mirroring the sections of the rule editor above.Example Configuration
- palo-alto-rule — Targets requests to
openai-main/gpt-3-5-turbo-16kfromteam:everyone, applying Prisma AIRS guardrails on both LLM input and output. - mcp-test-rule — Targets requests to the
kubernetes-mcpMCP server fromteam:test-team(excluding a specific user), applying PII detection before tool invocation and Prisma AIRS after.
Rule Structure
custom_error_message placeholders
The when Block
The when block contains two main sections: target (what the request targets) and subjects (who is making the request):
If
when is empty ({}), the rule matches all requests.Target: Match by MCP Servers
Target: Match by MCP Servers
Target: Match by Models
Target: Match by Models
Target: Match by Metadata
Target: Match by Metadata
X-TFY-METADATA: {"environment": "production", "tier": "enterprise"}Target: Match by Specific MCP Tool
Target: Match by Specific MCP Tool
Subjects: Users with IN/NOT IN
Subjects: Users with IN/NOT IN
Combined Target and Subjects
Combined Target and Subjects
target and subjects conditions must match for the rule to apply.