Skip to main content
Prompt Guard allows you to intercept LLM requests and responses at the gateway layer — before they reach your AI provider or return to the client. This enables consistent content policy enforcement without modifying application code. Guards can be applied to request (what the user sends to the LLM) and response (what the LLM sends back).

Overview

Regex

Match patterns in prompt text and block or mask matching content. Supports custom patterns and built-in rules for common PII types.

Webhook

Forward request or response content to an external moderation service. The webhook can reject or rewrite the content.

AWS Bedrock Guardrails

Delegate content safety to AWS Bedrock Guardrails using a guardrail identifier, version, and region.

Google Model Armor

Delegate content safety to Google Cloud Model Armor using a template, project, and location.

Configuration placement

Prompt Guard is configured under policies.ai.promptGuard on a route, applied to an AI backend:

Regex-based filtering

Use the regex guard to match patterns in prompts and responses. The request and response fields each accept a list of guard entries. Specify action: reject to block matching content.

Built-in patterns

Agentgateway ships with built-in patterns for common PII types. Reference them with the builtin key:

Custom patterns

Custom patterns accept any regular expression via the pattern field:

Custom rejection responses

Rejection responses are fully configurable. Return JSON errors compatible with OpenAI-style clients:

Header operations

Rejection responses support three header operations:

Testing regex guards

Send a request containing a blocked pattern:
Test that the response guard blocks LLM output containing emails:

Webhook-based validation

Forward request or response content to an external moderation service. The webhook can reject content or allow it through:
By default, request headers are not forwarded to the webhook. Use forwardHeaderMatches to specify which headers to include — each entry is a header name with an optional regex value matcher.

Provider integrations

Delegate content moderation to AWS Bedrock Guardrails. Configure with a guardrail identifier, version, and the AWS region:
AWS credentials must be available in the environment (e.g. via IAM role, environment variables, or the default credential chain).

Running the prompt guard example

The example configures request guards for SSN and Social Security patterns, plus a response guard for the email built-in pattern, with JSON rejection responses compatible with OpenAI clients.