For more granular control over pattern redaction, you can create custom patterns using Portkey’s Regex Match guardrail with redaction capabilities. This allows you to define specific regex patterns for sensitive information unique to your use case.Documentation Index
Fetch the complete documentation index at: https://portkey-docs-mintlify-bedrock-guardrails-docs-36443.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Setting Up Custom Regex Patterns

-
Navigate to Guardrails: Go to the
Guardrailspage and clickCreate - Select Regex Match: Choose the “Regex Replace” guardrail from the BASIC category
-
Configure the Pattern:
- Regex Rule: Enter your regex pattern to match specific data (e.g.,
\b\d{3}-\d{2}-\d{4}\bfor SSN patterns) - Replacement Text: Define what to replace matches with (e.g.,
[REDACTED],*****,[SSN_HIDDEN])
- Regex Rule: Enter your regex pattern to match specific data (e.g.,
- Save the Guardrail: Name your guardrail and save it to get the associated Guardrail ID
Common Regex Patterns for Sensitive Data
| Pattern Type | Regex Pattern | Replacement Example |
|---|---|---|
| Credit Card | \b\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}\b | [CREDIT_CARD] |
| Social Security Number | \b\d{3}-\d{2}-\d{4}\b | [SSN_REDACTED] |
| Phone Numbers | \b\d{3}[-.]\d{3}[-.]\d{4}\b | [PHONE_HIDDEN] |
| Email Addresses | \b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b | [EMAIL_REDACTED] |
| Custom Employee IDs | EMP-\d{6} | [EMPLOYEE_ID] |
Adding to Your Config
Once you’ve created your custom regex pattern guardrail, add it to your Portkey config:You can add the same guardrail to both
before_request_hooks (input guardrails) and after_request_hooks (output guardrails) to scan and redact regex patterns in both user inputs and LLM responses.Example Implementation
- NodeJS
- Python

