Skip to content

fix(platform): detect non–US-style addresses in PII filter - #1627

Merged
larryro merged 1 commit into
mainfrom
fix/pii-address-multilingual
Apr 26, 2026
Merged

larryro merged 1 commit into
mainfrom
fix/pii-address-multilingual

Conversation

@larryro

@larryro larryro commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The address regex in pii_patterns.ts only matched US/UK ordering (NUMBER NAME KEYWORD), so inputs like street dieng atas no 02G or Hauptstrasse 12 reported "No PII detected".
  • Extended the pattern with two more shapes: keyword-first international (Jalan/street/Rue … no/nr/# NUMBER) and German compound (Hauptstrasse 12, Bahnhofstr. 5). Allowed alphanumeric house numbers (02G, 12B).
  • Keyword-first variant requires an explicit no/nr/number/# marker to avoid false-positives like street art is cool 5.
  • Added 11 unit tests including the exact Bug: PII not detecting the address #1473 input as a regression case and negative tests.

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 pass
  • npx tsc --noEmit clean
  • npm run lint --workspace=@tale/platform clean
  • Manual UI repro per Bug: PII not detecting the address #1473 steps: paste i live in street dieng atas no 02G malang jawa timur indonesia into Settings → Governance → PII Protection → Test detection; expect [ADDRESS] badge for street dieng atas no 02G.
  • Manual: paste 123 Main Street, Hauptstrasse 12, Jalan Sudirman No 15 — each should detect.
  • Manual: paste street art is cool 5 days — should NOT detect (false-positive guard).

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced address detection pattern to recognize additional address formats with improved accuracy
    • Added support for international address variants, multiple street type keywords, and alternative number markers
    • Reduced false positives in address pattern matching
  • Tests

    • Added comprehensive test coverage for address detection across multiple formats, locales, and edge cases

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).
@coderabbitai

coderabbitai Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes expand PII address detection to fix a bug where address patterns were not being detected. The regex pattern in pii_patterns.ts is updated from a single narrow regex to a combined pattern supporting multiple address formats, street-type keywords with optional abbreviations, keyword-first formats with number markers (no/nr/number/#), and German compound address variants. Concurrently, a comprehensive test suite is added to validate detection across locale and format variants, confirm false-negative prevention for incomplete patterns, and verify scrubPii correctly masks detected addresses with the [ADDRESS] placeholder.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Rationale

The 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)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(platform): detect non–US-style addresses in PII filter' directly and clearly summarizes the main objective—expanding address detection to cover non-US formats, which aligns with the core changes made to the address regex pattern in pii_patterns.ts.
Linked Issues check ✅ Passed The PR directly addresses issue #1473 by expanding the address regex to detect international address formats (keyword-first forms and German compound words) that previously went undetected, and includes comprehensive unit tests validating the improvements.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing address PII detection: the regex pattern enhancements in pii_patterns.ts and corresponding test coverage in pii_patterns.test.ts are both clearly aligned with the linked issue #1473.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pii-address-multilingual

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 58fb561 and dfa7166.

📒 Files selected for processing (2)
  • services/platform/convex/governance/pii/__tests__/pii_patterns.test.ts
  • services/platform/convex/governance/pii/pii_patterns.ts

Comment on lines +189 to +193
it('detects "1234 5th Ave"', () => {
const matches = detectPii('1234 5th Ave', addressPatterns);
expect(matches).toHaveLength(1);
expect(matches[0].matchedText).toBe('1234 5th Ave');
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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.

Suggested change
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.

@larryro
larryro merged commit f943ad5 into main Apr 26, 2026
21 of 22 checks passed
@larryro
larryro deleted the fix/pii-address-multilingual branch April 26, 2026 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: PII not detecting the address

1 participant