From c776b20585ec54747a14eff8446a666f27cb7b1f Mon Sep 17 00:00:00 2001 From: siddharthsambharia-portkey Date: Mon, 25 Aug 2025 15:51:27 +0530 Subject: [PATCH 1/2] small fix --- docs.json | 1 + integrations/guardrails/regex.mdx | 99 ++++++++++++++++++++++++++++ product/guardrails/pii-redaction.mdx | 12 ++-- 3 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 integrations/guardrails/regex.mdx diff --git a/docs.json b/docs.json index d9a8be99..3b10e77a 100644 --- a/docs.json +++ b/docs.json @@ -374,6 +374,7 @@ "integrations/guardrails/palo-alto-panw-prisma", "integrations/guardrails/pillar", "integrations/guardrails/prompt-security", + "integrations/guardrails/regex", "integrations/guardrails/bring-your-own-guardrails" ] }, diff --git a/integrations/guardrails/regex.mdx b/integrations/guardrails/regex.mdx new file mode 100644 index 00000000..f2cf1edf --- /dev/null +++ b/integrations/guardrails/regex.mdx @@ -0,0 +1,99 @@ +--- +title: "Redact Custom Regex Patterns" +description: "Redact custom patterns with Regex in Portkey." +--- + +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. + +### Setting Up Custom Regex Patterns + + + + + +1. **Navigate to Guardrails**: Go to the `Guardrails` page and click `Create` +2. **Select Regex Match**: Choose the "Regex Match" guardrail from the BASIC category +3. **Configure the Pattern**: + - **Regex Rule**: Enter your regex pattern to match specific data (e.g., `\b\d{3}-\d{2}-\d{4}\b` for SSN patterns) + - **Replacement Text**: Define what to replace matches with (e.g., `[REDACTED]`, `*****`, `[SSN_HIDDEN]`) + - **Enable Redact**: Toggle the "Redact" option to `ON` + - **Inverse**: Keep this `OFF` unless you want to redact everything except the pattern + +4. **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: + +```json +{ + "before_request_hooks": [ + {"id": "your-guardrail-id"} + ], + "after_request_hooks": [ + {"id": "your-guardrail-id"} + ] +} +``` + + +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 + + + +```js +const portkey = new Portkey({ + apiKey: "PORTKEY_API_KEY", + config: "pc-***" // Config with custom regex pattern redaction +}); + +const response = await portkey.chat.completions.create({ + model: "@your-model-slug", + messages: [ + { + role: "user", + content: "My SSN is 123-45-6789 and credit card is 4532-1234-5678-9012" + } + ] +}); +``` + + +```py +portkey = Portkey( + api_key="PORTKEY_API_KEY", + config="pc-***" # Config with custom regex pattern redaction +) + +response = portkey.chat.completions.create( + model="@your-model-slug", + messages=[ + { + "role": "user", + "content": "My SSN is 123-45-6789 and credit card is 4532-1234-5678-9012" + } + ] +) +``` + + + +With the custom regex guardrail configured, the input would be automatically transformed to: +``` +"My SSN is [SSN_REDACTED] and credit card is [CREDIT_CARD]" +``` diff --git a/product/guardrails/pii-redaction.mdx b/product/guardrails/pii-redaction.mdx index 612c1bf5..afa8ccb1 100644 --- a/product/guardrails/pii-redaction.mdx +++ b/product/guardrails/pii-redaction.mdx @@ -23,7 +23,7 @@ Redact `Phone number`, `Email addresses`, `Location information`, `IP addresses` Based on Patronus's EnterprisePII dataset, this guardrail can detect and redact confidential information typically found in business documents like meeting notes, commercial contracts, marketing emails, performance reviews, and more - + Pangea's redact feature can redact PII like geographic locations, payment card industry (PCI) data, and many other types of sensitive information, with support for rule customization @@ -173,10 +173,6 @@ You can track request transformations through two key indicators in the request/ - Maintain records of what types of PII you're scanning for - Document any specific compliance requirements being addressed -4. **Custom Regex Testing**: - - Test your regex patterns thoroughly before deploying - - Use regex testing tools to validate pattern accuracy - - Consider edge cases and variations in data formats ## Security Considerations @@ -214,13 +210,13 @@ If you experience issues: -For pre-built guardrails, redaction patterns are standardized. However, you can create fully custom patterns using Portkey's Regex Match guardrail with redaction enabled. +Currently, redaction patterns are standardized and not customizable. -Each instance receives a numbered identifier (e.g., `{{EMAIL_ADDRESS_1}}`, `{{EMAIL_ADDRESS_2}}`, etc.) or your custom replacement text for regex-based redaction. +Each instance receives a numbered identifier (e.g., `{{EMAIL_ADDRESS_1}}`, `{{EMAIL_ADDRESS_2}}`, etc.). -Impact varies by guardrail provider and request complexity. Custom regex patterns with complex expressions may add minimal latency. +Impact varies by guardrail provider and request complexity. Custom regex patterns with complex expressions may add minimal latency. Yes, the feature works with any LLM supported by Portkey. From 6b6b02bed828abb498cca86ab4fd65c40ade512c Mon Sep 17 00:00:00 2001 From: siddharth Sambharia Date: Mon, 25 Aug 2025 23:51:36 +0530 Subject: [PATCH 2/2] Update regex.mdx --- integrations/guardrails/regex.mdx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/integrations/guardrails/regex.mdx b/integrations/guardrails/regex.mdx index f2cf1edf..0feeac90 100644 --- a/integrations/guardrails/regex.mdx +++ b/integrations/guardrails/regex.mdx @@ -1,5 +1,5 @@ --- -title: "Redact Custom Regex Patterns" +title: "Replace Custom Regex Patterns" description: "Redact custom patterns with Regex in Portkey." --- @@ -12,12 +12,10 @@ For more granular control over pattern redaction, you can create custom patterns 1. **Navigate to Guardrails**: Go to the `Guardrails` page and click `Create` -2. **Select Regex Match**: Choose the "Regex Match" guardrail from the BASIC category +2. **Select Regex Match**: Choose the "Regex Replace" guardrail from the BASIC category 3. **Configure the Pattern**: - **Regex Rule**: Enter your regex pattern to match specific data (e.g., `\b\d{3}-\d{2}-\d{4}\b` for SSN patterns) - **Replacement Text**: Define what to replace matches with (e.g., `[REDACTED]`, `*****`, `[SSN_HIDDEN]`) - - **Enable Redact**: Toggle the "Redact" option to `ON` - - **Inverse**: Keep this `OFF` unless you want to redact everything except the pattern 4. **Save the Guardrail**: Name your guardrail and save it to get the associated Guardrail ID