AI Gateway Guardrails checks traffic between your application and your model providers. Guardrails uses @cf/meta/llama-guard-3-8b to check for content hazards (S1 to S14). It uses @cf/meta/prompt-guard-2-86m to check prompts for prompt injection ↗︎ (P1).
Configure one policy per gateway and apply it to supported traffic across providers, including OpenAI, Anthropic, DeepSeek, and Workers AI. Set the action for each supported category to Flag, Block, or Ignore.
Use AI Gateway Logs to review evaluations for logged requests. Prompt and response bodies are available only when payloads are stored.
Guardrails applies your configured policy in three steps:
- Intercept traffic: AI Gateway proxies requests and responses between your application and its model provider.
- Evaluate prompts and responses:
- User prompts: Guardrails checks prompts for content hazards and prompt injection. If a prompt matches a category set to Block, it does not reach the model provider.
- Model responses: Guardrails checks eligible response text for content hazards. It skips responses from embedding and unknown model types. For streaming requests, the REST API evaluates responses without enforcing the response policy. Gateway endpoints buffer streamed responses for evaluation and return a single non-streamed payload.
- Apply configured actions: Flag marks a match for review without blocking it. Ignore takes no action for that category. A block returns error code
2016for a prompt or2017for a response.
For setup steps, hazard categories, supported model types, and streaming behavior, refer to Set up Guardrails.