Repository navigation
fix(platform): detect non–US-style addresses in PII filter - #1627
Conversation
The address regex only matched US/UK ordering (NUMBER NAME KEYWORD), so inputs like "street dieng atas no 02G" or "Hauptstrasse 12" reported no PII. Extended the pattern to also cover keyword-first international addresses (requires a no/nr/number/# marker to keep false positives down) and German compound-word style. Allowed alphanumeric house numbers (02G).
📝 WalkthroughWalkthroughThe changes expand PII address detection to fix a bug where address patterns were not being detected. The regex pattern in Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes RationaleThe regex pattern expansion involves multiple sub-patterns combined with OR logic, including street type keywords, abbreviation handling, and locale-specific variants that require careful review to verify correctness. The test suite, while somewhat repetitive in structure, includes diverse address formats and edge cases that need validation. The changes are contained within the PII pattern module with no API or structural modifications, but the density of regex logic and breadth of test cases warrant moderate review effort. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@services/platform/convex/governance/pii/__tests__/pii_patterns.test.ts`:
- Around line 189-193: Add a regression test that verifies dotted number-first
street abbreviations are detected: create a new it block (e.g., it('detects
"1234 5th Ave."', ...) ) that calls detectPii('1234 5th Ave.', addressPatterns)
and asserts matches.length === 1 and matches[0].matchedText === '1234 5th Ave.';
this mirrors the existing undotted test but ensures the st\.? / ave\.? branch
handles the trailing dot.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: d8811bbc-ecf8-4c59-8165-d818365d88d0
📒 Files selected for processing (2)
services/platform/convex/governance/pii/__tests__/pii_patterns.test.tsservices/platform/convex/governance/pii/pii_patterns.ts
| it('detects "1234 5th Ave"', () => { | ||
| const matches = detectPii('1234 5th Ave', addressPatterns); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0].matchedText).toBe('1234 5th Ave'); | ||
| }); |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Add a regression test for dotted number-first abbreviations (St. / Ave.).
This suite is solid, but adding one dotted-abbreviation case here would prevent regressions for the st\.? / ave\.? branch.
✅ Suggested test addition
it('detects "1234 5th Ave"', () => {
const matches = detectPii('1234 5th Ave', addressPatterns);
expect(matches).toHaveLength(1);
expect(matches[0].matchedText).toBe('1234 5th Ave');
});
+
+ it('detects dotted abbreviation "123 Main St."', () => {
+ const matches = detectPii('123 Main St.', addressPatterns);
+ expect(matches).toHaveLength(1);
+ expect(matches[0].matchedText).toBe('123 Main St.');
+ });📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it('detects "1234 5th Ave"', () => { | |
| const matches = detectPii('1234 5th Ave', addressPatterns); | |
| expect(matches).toHaveLength(1); | |
| expect(matches[0].matchedText).toBe('1234 5th Ave'); | |
| }); | |
| it('detects "1234 5th Ave"', () => { | |
| const matches = detectPii('1234 5th Ave', addressPatterns); | |
| expect(matches).toHaveLength(1); | |
| expect(matches[0].matchedText).toBe('1234 5th Ave'); | |
| }); | |
| it('detects dotted abbreviation "123 Main St."', () => { | |
| const matches = detectPii('123 Main St.', addressPatterns); | |
| expect(matches).toHaveLength(1); | |
| expect(matches[0].matchedText).toBe('123 Main St.'); | |
| }); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@services/platform/convex/governance/pii/__tests__/pii_patterns.test.ts`
around lines 189 - 193, Add a regression test that verifies dotted number-first
street abbreviations are detected: create a new it block (e.g., it('detects
"1234 5th Ave."', ...) ) that calls detectPii('1234 5th Ave.', addressPatterns)
and asserts matches.length === 1 and matches[0].matchedText === '1234 5th Ave.';
this mirrors the existing undotted test but ensures the st\.? / ave\.? branch
handles the trailing dot.
Summary
NUMBER NAME KEYWORD), so inputs likestreet dieng atas no 02GorHauptstrasse 12reported "No PII detected".Jalan/street/Rue … no/nr/# NUMBER) and German compound (Hauptstrasse 12,Bahnhofstr. 5). Allowed alphanumeric house numbers (02G,12B).no/nr/number/#marker to avoid false-positives likestreet art is cool 5.Why not a library
Investigated
libpostal, Microsoft Presidio,redact-pii,openredaction, Transformers.js — none fit our constraints (browser + Convex Node, offline, small footprint). libpostal needs a ~4 GB data file and has no WASM port; Presidio is Python-only; the JS PII libs all use the same US-English-only address regex we already had. Full plan / alternatives matrix in .claude/plans/stateless-wobbling-steele.md (local).If higher-accuracy multilingual address detection becomes a real product need, the architectural answer is a server-side libpostal Convex action — out of scope here.
Known limitation
The regex matches the structurally-anchored part of an address (street + house number). Trailing geographic context like
malang jawa timur indonesia(city/province/country) is not masked, because regex can't tell those words apart from ordinary nouns without semantic understanding. Industry tools (Presidio, Google DLP) use NER for that.Closes #1473
Test plan
bunx vitest --run --project server pii_patterns— 44/44 passnpx tsc --noEmitcleannpm run lint --workspace=@tale/platformcleani live in street dieng atas no 02G malang jawa timur indonesiainto Settings → Governance → PII Protection → Test detection; expect[ADDRESS]badge forstreet dieng atas no 02G.123 Main Street,Hauptstrasse 12,Jalan Sudirman No 15— each should detect.street art is cool 5 days— should NOT detect (false-positive guard).Summary by CodeRabbit
Bug Fixes
Tests