From ce96d78203d5a80e0d7df5ea315b3a956bb076ae Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Thu, 5 Mar 2026 20:19:29 -0800 Subject: [PATCH] fix: Address Greptile review feedback - Tighten ca_postal_code keyword_pattern: replace broad "address" with specific compound terms (mailing/street/shipping/home address) - Add missing "PIPEDA" tag to policy_templates.json for discoverability - Add us_phone pattern to test_ca_policy_e2e.py setup to match deployed template - Add phone number e2e test for complete coverage Co-Authored-By: Claude Opus 4.6 --- .../litellm_content_filter/patterns.json | 2 +- policy_templates.json | 1 + .../content_filter/test_ca_policy_e2e.py | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/patterns.json b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/patterns.json index 32296c6da1c..c79ed2244c9 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/patterns.json +++ b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/patterns.json @@ -595,7 +595,7 @@ "pattern": "\\b[ABCEGHJ-NPRSTVXY]\\d[ABCEGHJ-NPRSTV-Z][\\-\\s]?\\d[ABCEGHJ-NPRSTV-Z]\\d\\b", "category": "Canadian PII Patterns", "description": "Detects Canadian postal codes (A1A 1A1 format, excludes invalid first-letter characters per Canada Post spec)", - "keyword_pattern": "\\b(?:postal\\s*code|zip\\s*code|mailing\\s*address|address|code\\s*postal|postcode)\\b", + "keyword_pattern": "\\b(?:postal\\s*code|zip\\s*code|mailing\\s*address|street\\s*address|shipping\\s*address|home\\s*address|code\\s*postal|postcode)\\b", "allow_word_numbers": false }, { diff --git a/policy_templates.json b/policy_templates.json index ad30e908fdd..c9591dd7a4a 100644 --- a/policy_templates.json +++ b/policy_templates.json @@ -2704,6 +2704,7 @@ "tags": [ "PII Protection", "Canada", + "PIPEDA", "FIPPA" ], "estimated_latency_ms": 1 diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/content_filter/test_ca_policy_e2e.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/content_filter/test_ca_policy_e2e.py index f5efd238cfe..6be78b3c856 100644 --- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/content_filter/test_ca_policy_e2e.py +++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/content_filter/test_ca_policy_e2e.py @@ -68,6 +68,11 @@ class TestCanadianPIIPolicyE2E: pattern_name="email", action=ContentFilterAction.MASK, ), + ContentFilterPattern( + pattern_type="prebuilt", + pattern_name="us_phone", + action=ContentFilterAction.MASK, + ), ContentFilterPattern( pattern_type="prebuilt", pattern_name="ca_postal_code", @@ -344,6 +349,26 @@ class TestCanadianPIIPolicyE2E: assert "REDACTED" not in output assert output == text + # ===================== + # Phone Number tests + # ===================== + + @pytest.mark.asyncio + async def test_phone_number_masked(self): + """North American phone number is detected and masked""" + guardrail = self.setup_canadian_guardrail() + + text = "Call me at (416) 555-1234 to discuss." + result = await guardrail.apply_guardrail( + inputs={"texts": [text]}, + request_data={}, + input_type="request", + ) + output = result.get("texts", [])[0] + + assert "REDACTED" in output + assert "(416) 555-1234" not in output + # ===================== # Postal Code tests # =====================