- Built-in fields - Add headers, query parameters, or body fields directly in the AI Gateway config
- Find & Replace - Use regex patterns to transform request content
Built-in request modification
The AI Gateway config includesheaders, query_params, and body fields for simple modifications without needing a separate action.
Adding headers
Add custom headers to all requests sent to providers:policy.yaml
Adding query parameters
Append query parameters to provider requests (useful for providers that require API versioning):policy.yaml
Adding body fields
Merge additional fields into the JSON request body. This is useful for enforcing default parameters:policy.yaml
Combining built-in fields
You can use all three together:policy.yaml
Advanced: find and replace
For more complex transformations like PII redaction or content rewriting, use therequest-body-find-replace action. It runs before the AI Gateway and uses regex patterns to modify the request body.
policy.yaml
Redacting PII from prompts
Prevent sensitive information from being sent to AI providers:policy.yaml
Injecting system instructions
Append instructions to existing system messages:policy.yaml
$1 to preserve the original system message content.
Common PII patterns
| Pattern | Matches |
|---|---|
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} | Email addresses |
\b\d{3}-\d{2}-\d{4}\b | US Social Security Numbers |
\b\d{3}[-.\s]?\d{3}[-.\s]?\d{4}\b | US Phone numbers |
\b\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}\b | Credit card numbers |
"api_key":\s*"[^"]*" | JSON API key fields |
"password":\s*"[^"]*" | JSON password fields |
Using capture groups
Preserve parts of the matched text:Dynamic patterns with CEL
Bothfrom and to fields support CEL expressions:
Next steps
- Modifying Responses - Sanitize responses and streaming content
- Request Body Find & Replace Reference - Full configuration options
- Configuration Schema - All AI Gateway config fields