Availability
Guardrails for agent traffic are available from Tyk AI Studio 2.3.0.
Overview
A guardrail is a filter that sends text to a detection provider instead of running a script. You select a provider, the detectors, and the action to take on a match. You do not write code. A guardrail attaches and runs in the same way as a script filter:- You attach it to LLMs, chat rooms, and tools. Refer to Filters.
- It runs on requests, on responses, and on tool arguments and tool results. Streamed responses are also included.
- It runs in AI Studio and on each Edge Gateway.
- Each match records a compliance event.
In the Community Edition, AI Studio does not run a guardrail that you create and attach. The guardrail lets all content through, and AI Studio logs a warning, the same as for a script filter. App capabilities, exceptions, and prompt templates have no effect.

Default Guardrails
A new Enterprise installation includes five guardrails that use the built-in pattern library:
They have no effect until you attach them.
- AI Studio creates each one by name only if it does not exist. It does not change a default guardrail that you edited, and it does not create a deleted guardrail again.
- An upgraded installation gets Prompt injection in tool results (quarantine) on its next start.
- To skip them on a new installation, set SKIP_FILTER_DEFAULTS=true.
Actions
All actions record a compliance event for each detector that matches. Quarantine and Log and raise event are available from Tyk AI Studio 2.3.0. Refer to Quarantine and Alerts.
Redaction
Redaction applies to request-side filters only: LLM requests, chat messages, and tool arguments.
You can use these variables in the placeholder:
{{type}}: the detector name in upper case, such asEMAILorAWS_ACCESS_KEY{{category}}: the category, such asPIIorSECRETS
Messages to Inspect
On an LLM request, Messages to inspect selects the messages that the provider gets:- All user messages (default)
- User text of the current turn: the user text since the model last replied
- System and user messages
- Every message, including assistant turns
Provider Failures
If the provider fails controls what happens when the provider returns an error or the call takes longer than the timeout:- On request filters, the default is to block. This is fail closed. Request filters include filters on tool arguments.
- On response filters, the default is to let the content through. This is fail open. Response filters include filters on tool results.
guardrail.error compliance event.
From 2.3.0, the fail mode applies only to an ordinary request. A request is ordinary when it has at most budget.single_call_chars characters to scan and needs few provider calls. For a per-message provider, such as Lakera Guard or Bedrock Guardrails, this means at most four messages and four tool results.
On a larger request, a provider failure leaves the affected text unscanned. AI Studio then applies the filter’s action to the unscanned text, the same as to a finding. For this reason, a fail-open filter can block a large request during a provider outage.
To bring more requests under the fail mode, raise budget.single_call_chars. Refer to Budgets and the Verdict Cache.
Sometimes only the call for the tool results fails on an ordinary request. With fail closed, AI Studio then quarantines the tool results, and the request continues.
When a provider call does not return 100 ms after its timeout, AI Studio stops waiting and counts it as a timeout. If an external provider does this often, AI Studio suspends calls to it for 10 seconds. A suspended call fails at once and the fail mode applies.
Streamed Responses
On a streamed response, a guardrail does not examine each chunk. It examines the accumulated response each time the response gets longer by N characters. The default N is 250 for the built-in pattern library and 1000 for external providers. To change it, set Streaming: evaluate every N characters. The guardrail also examines the full response once when the stream ends. This makes sure that it examines a response that is shorter than N. If the guardrail blocks during the stream, AI Studio stops the stream. If it blocks at the end of the stream, AI Studio ends the stream with an error and records the block. But the client already has the chunks that AI Studio sent before. From 2.3.0, response guardrails screen all stream formats: OpenAI chat completions and the Responses API, Anthropic, Google, Ollama, and Bedrock through the bridges. A block ends the stream with the error event of the vendor, so the vendor SDK raises an error.Budgets and the Verdict Cache
A sender controls the size of a request. A tool result can have any length, and an agent sends its full history on each turn. Two mechanisms keep the cost of scanning under control. The verdict cache keeps each provider verdict on a request segment, such as one message or one tool result. AI Studio answers the history that an agent sends again from the cache, so the provider examines each segment one time.- AI Studio reuses a verdict only for the same filter version, provider version, kind of segment, text, and App.
- It caches only the verdicts of successful calls.
- It does not cache responses or Test panel results.
- To turn off the cache for one filter, clear Reuse verdicts for text already scanned (
cache: false). Do this for a provider whose verdict depends on more than the text.
budget settings limit the scan of one request:
AI Studio never treats text outside a budget as clean. It marks the text as unscanned and applies the filter’s action:
- Block blocks the request. For a tool result, it quarantines the tool result.
- Redact also blocks, or quarantines a tool result, because AI Studio cannot redact unscanned text.
- Quarantine replaces the segment.
- Log only records it.
400, 413, or 422.
The built-in pattern library is not subject to these budgets. It scans each segment in full, up to GUARDRAIL_LOCAL_MAX_SCAN_BYTES. Response filters use no cache and no budgets, and the fail mode decides each provider failure.
For the environment variables that size the verdict cache and the built-in library scans, refer to Environment Variables.
When a Guardrail Blocks a Request
From 2.3.0, the caller gets HTTP400 with the filter name, the block message, the reason, and the request ID. For example, for a filter named Prompt attacks:
/llm/ endpoints, the JSON body also contains reason_code, reason, filter, and request_id. The X-Tyk-AI-Guardrail-Reason response header contains the reason code. Match on the reason code instead of the message text.
The message of a script filter block does not change.
In Compliance > Filter Events, the details of a guardrail event start with a summary of what happened. Why gives the causes, and Fix gives up to two actions.
If a guardrail blocks legitimate traffic, refer to Tune Guardrails.