- Response sanitization - Strip internal details or inappropriate content
- PII redaction - Remove sensitive information from outputs
- Adding disclaimers - Append legal notices or warnings
- Content transformation - Modify response formats
Available actions
Use different actions depending on whether responses are streaming:| Action | Phase | Use Case |
|---|---|---|
| response-body-find-replace | on_http_response | Non-streaming responses |
| sse-find-replace | on_event_stream_message | Streaming responses (stream: true) |
Non-streaming responses
For standard (non-streaming) responses, useresponse-body-find-replace on the on_http_response phase:
policy.yaml
Streaming responses
When clients request streaming responses (stream: true), providers return Server-Sent Events (SSE). Use sse-find-replace on the on_event_stream_message phase to modify content in real-time:
policy.yaml
field parameter specifies which SSE field to modify. Valid values are data (default) and retry.
Redacting PII from responses
Prevent sensitive information in outputs from reaching your users.Redact multiple PII patterns
policy.yaml
Adding disclaimers
Append legal disclaimers or warnings to AI-generated content.policy.yaml
Sanitizing error messages
Remove internal error details from responses before sending to clients:policy.yaml
Common patterns for responses
| Pattern | Matches | ||
|---|---|---|---|
\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 | ||
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} | Email addresses | ||
| `“(error | stack_trace | internal)”:\s*”[^”]*“` | Internal error fields |
Handling both streaming and non-streaming
If your API supports both modes, configure both phases:policy.yaml
Next steps
- Modifying Requests - Redact PII and inject prompts
- Response Body Find & Replace Reference - Full configuration options
- SSE Find & Replace Reference - Full configuration options for streaming