Skip to content

Guardrails

Definition

A guardrail is a check applied to a request or a response that returns a verdict. Guardrails enforce data-protection, output-policy and prompt-injection rules before a request reaches the provider, or before a response reaches the client.

Function

Guardrails let a gateway mask, flag or block content according to policy, independent of the model that answers.

Tiers

The gateway runs guardrails in two tiers:

  • Tier 1 — runs in-process inside the gateway (pattern, keyword and rule-based checks).
  • Tier 2 — calls a detection sidecar inside the Myra perimeter (NLP-based checks such as PII detection and prompt-injection classification).

Tier 1 always runs before Tier 2. Within a tier, guardrails run in their configured order. A configured Tier 2 guardrail always runs; if its sidecar is unreachable, it returns error.

Verdict lifecycle

Verdict Effect
pass No match. The pipeline continues.
scrubbed Match; the guardrail rewrites the content. The provider never sees the original value. Masking is skipped on a wholly-local Myra model leg.
flagged Match; the request continues and the match is recorded. A flag on a top-level turn also creates a review item.
block Match; the request is rejected with an assistant message that says it was blocked. The pipeline stops.
error The guardrail failed to run. Its fail_open setting decides: pass when true, block when false.

scrubbed and flagged are non-terminal. The action field of a guardrail configuration (scrub, flag, block) selects the outcome; the verdict is what the guardrail returns.

Matches in earlier conversation turns

A request-phase block guardrail fires on the new user turn. Chat clients resend the whole conversation on every request, so a value that was matched once would otherwise block every later turn of the same conversation. When the match exists only in earlier history, the gateway removes it before the request leaves Myra and the request continues. The new user turn, system and developer messages, and every top-level field are never rewritten by this step.

Detector type What happens to a history-only match
keyword, regex, presidio The matched text is masked in the earlier turn.
All other per-message types The earlier turn's text is replaced by the placeholder [earlier message removed by guardrail policy] (a turn without tool blocks becomes a single placeholder text block; images and other parts are removed). Role, position and tool-call ids are kept, so the conversation stays valid for the provider. An Anthropic tool_use block's input is emptied to {} and so are an OpenAI tool call's function.arguments, the legacy function_call.arguments and a Responses function_call item's arguments (ids and names are kept).
json_schema, gibberish, language The request is blocked, because these have no per-message meaning. How a match in the file-tool exchange the gateway re-inserted for an earlier file edit is treated is described in Earlier conversation turns.

The request is blocked as before whenever the match is in the new user turn, or the history cannot be resolved safely: a malformed message array, a match that remains after masking, dropping or emptying tool-call arguments, a failed detector call, or when the resolution exceeds its bounds (24 detector calls or 3 seconds per request, across all detectors). After removal the whole request is scanned again and must come back clean.

A detector with fail_open set still blocks when the resolution step itself fails: the detector already reported a block, and an unverifiable resolution does not turn it into a pass.

The placeholder above and the other replacement texts the gateway's protection controls write (the text a keyword or regex scrub guardrail inserts, for example [REDACTED], the <TYPE> masks the gateway writes for the entity types it knows (the NLP PII Detector; the mask of an unknown type is read as ordinary text) and the protection tokens of the PII Protector and the Custom PII detector) are never a match for a keyword or regex guardrail, so removing a turn cannot make a later guardrail refuse the request. The same words typed by a user are still matched, and other texts the gateway adds to tool output, such as the notices for withheld content, are checked like any tool output: in an earlier turn a match there is masked and the conversation continues. A keyword or pattern that matches the whole of the gateway's text is not exempt; the request is then refused rather than passed. Tool-call arguments the gateway empties to {} when it removes an earlier turn are not exempt either: a keyword or pattern that matches {} still refuses the request.

Every removal is audited in the request log as the protection marker guardrail_history_removed: for each detector, the message positions (0-based) and whether each was masked or dropped. It records positions and the action, never the matched text. It does not count as a protection gap. The item carries inserted (always removed) when the gateway left the exchanges it re-inserted for earlier file edits out of the request; how request guardrails treat a match in that exchange is described in Earlier conversation turns. The marker is size-capped (4096 bytes) but every detector that changed the history always keeps its own item: when the list is too long, the entries of all items are trimmed to a common length and each trimmed item carries truncated: true (an item can end up with "entries": []). In the extreme case that even the entry-less items of all detectors do not fit, the request is blocked rather than left unaudited.

Residual: a direct-API client can wrap a forbidden question in a tool_use / tool_result pair so that it moves into history. It is then masked or removed and never sent to the provider, but the request is not refused.

Targets

Each guardrail inspects the request, the response, or both.

Logging

Every verdict is recorded in the request log. Guardrails that fired are listed under detectors_fired; a block records blocked_by and block_reason. A guardrail never discloses the value it protects: for a keyword, pattern, Custom PII or jailbreak block the caller's refusal names only the detector, and the stored block_reason is redacted:<type>:<12 hex>. The guardrail activity reads available below the logs permission (REQUEST_LOGS_VIEW) omit block_reason altogether.

See also