Skip to main content

Guardrails overview

You're reading AI Gateway 1.0.0. The newest release is 1.2.0. Go to the newest release

Guardrails are policies that run in the LLM Proxy's request and response pipeline to validate, filter, or transform content before it reaches an LLM or is returned to the client.

Guardrails use the same underlying policy engine as API Gateway policies. Each guardrail declares which execution phases it participates in, and the engine calls the appropriate hook for each phase.

What guardrails do​

  • Content filtering: Block or flag requests and responses that violate configured topic, word, or content policies.
  • PII detection and masking: Detect and mask or redact personally identifiable information in prompts and responses.
  • Schema validation: Enforce structure on requests or responses using JSON Schema.
  • Pattern matching: Detect prohibited content using regular expressions.
  • Length and count limits: Enforce word count, sentence count, and byte length constraints on prompts and responses.
  • External validation: Delegate content validation to managed services such as AWS Bedrock Guardrails or Azure Content Safety.

Available guardrails​

GuardrailWhat it does
AWS Bedrock GuardrailValidates content against AWS Bedrock Guardrails for content filtering, topic detection, and PII masking
Azure Content SafetyValidates content against Azure Content Safety API for content moderation
Content Length GuardrailEnforces a maximum byte length on request or response content
JSON Schema GuardrailValidates request or response content against a JSON Schema
PII Masking Regex GuardrailDetects and masks PII using configurable regex patterns
Regex GuardrailValidates content against a regular expression pattern
Semantic Prompt GuardrailBlocks or allows prompts based on semantic similarity to configured allow or deny phrases
Sentence Count GuardrailEnforces a sentence count limit on request or response content
URL GuardrailValidates URLs found in request or response content
Word Count GuardrailEnforces a word count limit on request or response content

How guardrails execute​

When multiple guardrails are attached to an LLM Proxy, they run as an ordered chain across request and response phases. The AI Gateway's architecture — with a separate LLM Proxy chain and LLM Provider chain — means every request passes through two chains in sequence.

For a full explanation of phase execution, multi-guardrail ordering, and the dual-hop execution model specific to AI Gateway, see Guardrail execution order.

Was this page helpful?