Skip to main content
A guardrail checks a request or a response, and blocks it, masks part of it, or only logs what it found. Guardrails run on model requests and on MCP tool requests. POST /v2/agent_gateways/{id}/guardrails adds one. This guardrail masks Social Security numbers and email addresses before a request reaches the model:

Modes

Each guardrail runs in one or more of these modes, and each type runs in some of them:

Scope

A guardrail with always_on runs on every request. Any other guardrail runs on the requests that name it in guardrails:
A request can add guardrails this way. It cannot turn off a guardrail that runs on every request.

Built-In Guardrails

These types run on the instance itself, with no outside service: A custom_code guardrail defines apply_guardrail(inputs, request_data, input_type). It reads the texts in inputs["texts"] and returns allow(), block(reason), or modify(texts=...):

Provider Guardrails

These types send the request to an outside service, and need an account with it: lakera (Lakera Guard), presidio (Microsoft Presidio), bedrock (Amazon Bedrock Guardrails), and azure_content_safety (Azure AI Content Safety). A provider’s API key and AWS keys are write-only. No response returns them, and an update sends them again with the whole settings.

Blocking and Masking

How a block reaches the agent depends on the guardrail:
  • A content filter or tool permission guardrail fails a model request with 400 and its reason as the error message, such as Content blocked: us_ssn pattern detected.
  • A model judge fails it with 422 and LLM judge rejected response: score below threshold.
  • A custom code guardrail answers the request with its reason in place of the model’s response.
  • A block after a stream starts closes the stream before it completes.
  • A blocked tool request returns a tool result with isError: true.
A masking guardrail replaces each match before the request reaches the model. With the content filter, 123-45-6789 reaches the model as [US_SSN_REDACTED]. In a tool mode, it masks the tool’s arguments before they reach the server, or the tool’s result before it reaches the agent.