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 underpolicies.ai.promptGuard on a route, applied to an AI backend:
Regex-based filtering
Use theregex 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 thebuiltin key:
| Built-in name | Matches |
|---|---|
email | Email addresses |
ssn | US Social Security Numbers |
Custom patterns
Custom patterns accept any regular expression via thepattern 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:| Operation | Behavior |
|---|---|
set | Replace or create a header (overwrites existing value) |
add | Append a header value (allows multiple values for the same header) |
remove | Remove a header from the response |
Testing regex guards
Send a request containing a blocked pattern:Webhook-based validation
Forward request or response content to an external moderation service. The webhook can reject content or allow it through:forwardHeaderMatches to specify which headers to include — each entry is a header name with an optional regex value matcher.
Provider integrations
- AWS Bedrock Guardrails
- Google Cloud Model Armor
Delegate content moderation to AWS Bedrock Guardrails. Configure with a guardrail identifier, version, and the AWS region:
| Field | Description |
|---|---|
guardrailIdentifier | The Bedrock guardrail ID or ARN |
guardrailVersion | Version string, e.g. DRAFT or 1 |
region | AWS region where the guardrail is deployed |
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
SSN and Social Security patterns, plus a response guard for the email built-in pattern, with JSON rejection responses compatible with OpenAI clients.