Screen prompts with content moderation
Configure a content moderation policy that catches prompt injection and sensitive data, and choose the right action for each filter.
A content moderation policy catches risky prompts, like an injection attempt or a pasted card number, before they reach the model. It has three parts:
- Prompt injection protection looks for common injection and jailbreak phrasing, using patterns derived from the OWASP LLM Prompt Injection Prevention Cheat Sheet, including scrambled or encoded variants. You can set Messages to scan to All messages or User messages only (which skips developer-authored system prompts to avoid false positives). It’s free and adds very little latency.
- Sensitive info detection finds things like email addresses, phone numbers, credit card numbers, and well-known provider API keys. Most presets use fast pattern matching. Person names and addresses use language analysis, are in beta, and add latency.
- Custom content filters are your own regular expressions, such as an internal project code name.
Custom filters use JavaScript-style regular expressions. To keep checks fast, lookaheads, lookbehinds, backreferences, and patterns with heavy backtracking like (a+)+ are rejected when you save.
Each check runs on the prompt side only, on the text of messages, tool call arguments sent as strings, and prompt strings. Model responses, images, files, and some provider-specific content blocks aren’t scanned. The prompt injection docs list every field that’s skipped.
Pick an action
Each filter has an action:
- Redact: the matched text is replaced with a label, and the cleaned prompt goes to the model. “Refund the order for jane.doe@contoso.com” reaches the model as “Refund the order for [EMAIL]”.
- Block: the request is rejected with a
403before it reaches the model. - Flag: the request goes through unchanged, and the detection is recorded.
When several policies apply, the strictest action wins: block beats redact, and redact beats flag.
To review what was caught, open Logs. Requests with a guardrail detection show a shield icon on their row; hover it to see what was detected, or open the request to review each detection and mark false positives.
Check your understanding
You want prompt injection protection on a customer-facing chatbot, but you’re worried it will block real customers. What’s a safe way to start?
Apply it
Your support team pastes customer emails into an internal assistant. Legal wants email addresses and phone numbers kept away from model providers, but agents still need the assistant to work. What do you set up?
A content moderation policy with the email address and phone number presets set to redact, assigned to the support workspace (or its members).
Prompts still go through, with [EMAIL] and [PHONE] in place of the real values. Block would stop agents every time a ticket contains contact details.
Redaction replaces what the presets match, so contact details written in an unusual format can still get through. Responses aren’t scanned, so anything the assistant generates isn’t filtered.
Takeaway
Content moderation policies combine prompt injection detection, sensitive info presets, and custom regex filters, each with flag, redact, or block. They scan prompts, not responses, and the strictest action wins when policies overlap.
Try it live
OptionalFind a request with a shield icon on its row, hover it to see what was detected, then open it to review each detection.