RegEx
The RegEx Guardrail (regexp_guardrail) is a deterministic guardrail that checks whether the text matches a specified regular expression pattern. It can run in pre-generation (checking user input) and post-generation (checking AI responses and tool call arguments).
When to Use
Use this guardrail to: - Prevent users from submitting known banned patterns or phrases. - Block responses containing sensitive information (e.g., PII like emails, credit card numbers, or social security numbers). - Strip out or block system formatting leaks (e.g., matching unwanted markdown or raw JSON blocks).
Configurable Fields
| Field | Key | Type | Default | Description |
|---|---|---|---|---|
| RegEx Pattern | regexp_pattern |
Textfield | None | The regular expression pattern to match against, including delimiters. Example: /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/i (matches emails). |
| Violation Message | violation_message |
Textarea | The text contains invalid content matching the pattern: @pattern |
The message returned when a match is found. Supports the @pattern placeholder to display the matched pattern. |
How it Evaluates Outputs
When evaluated as a post-generation guardrail, it scans both the final assistant message body and any tool call arguments generated by the model. This prevents sensitive data or disallowed patterns from bypassing checks through structured tool inputs.
Decision Requests
On Decision requests the guardrail runs before and after generation. Before generation it scans the keys and values of the state, and each question's instructions and criteria; afterward, the chosen options and score legends. Question IDs, types, probabilities, scores, confidence and file contents are never scanned. A missing or invalid pattern fails the request with a setup error instead of passing it; in a global set the check is skipped with a logged warning.
Example Configuration
Below is an example configuration that checks for and blocks email addresses in either inputs or outputs:
id: regexp_guardrail
regexp_pattern: "/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/i"
violation_message: "Personally identifiable information (emails) is not allowed. Detected pattern: @pattern"