Skip to content

Help wanted: Improve and expand PII pattern coverage #75

Open

Description

@sam247

@atomicpages — wanted to get your thoughts on this before I start turning it into smaller issues or putting any tooling around it.

We've got 500+ detection patterns across different countries, regions and identifier types. The initial work was on getting coverage in place. I think the next stage should run along two tracks:

  1. Harden existing patterns

Work through existing patterns by country, region or identifier family and improve accuracy. Ideally this would include:

  • reviewing current regex and validator behaviour;
  • adding valid and invalid synthetic fixtures;
  • checking false positives and false negatives;
  • changing implementation only where tests demonstrate an improvement;
  • adding regression tests for changed behaviour.
  1. Add missing patterns and regional coverage

Give contributors with local or domain knowledge a clear route to add identifiers we’re currently missing. Ideally new patterns would include:

  • a reference for the identifier format or specification;
  • regex and/or validator implementation;
  • valid synthetic examples;
  • invalid and edge-case examples;
  • tests.

My thought is that this issue could act as the starting point, then we create smaller help wanted issues for individual countries, regions or pattern families once we have a repeatable format.

I’d be interested in your thoughts on how best to structure the test harness and contribution workflow around the new package structure. I also want to make this approachable for contributors who know a particular country’s identifiers or data formats but don’t necessarily know the whole OpenRedaction codebase.

No rush on this one — mainly wanted to get the idea down and get your thoughts before we start building around it and before my 5 day hiatus.

Activity

  1. added
    enhancement
    help wanted
    on Jul 10, 2026
  2. atomicpages commented on Jul 22, 2026

    @atomicpages
    Collaborator

    For sure, I already have some ideas we can probably iterate on quickly:

    • Add integration tests that pass through OpenRedaction. The benefit here is
      the contributor of focused on the outcome rather than the specifics of
      adding/amending a new regex. Something like this:

      it("should detect UAE Emirates ID", async () => {
        const detector = new OpenRedaction({ patterns: ["UAE_EMIRATES_ID"] });
        const result = await detector.detect("Emirates ID: 784-1990-1234567-1");
        expect(result.detections.some((d) => d.type === "UAE_EMIRATES_ID")).toBe(
          true,
        );
      });
    • Having a coverage report

      export interface PIIPattern {
        type: string;
        regex: RegExp;
        priority: number;
        validator?: (match: string, context: string) => boolean;
        placeholder: string;
        description?: string;
        severity?: "critical" | "high" | "medium" | "low";
        // NEW:
        country?: string; // ISO 3166-1 alpha-2, e.g. "AE"
        region?: string; // "middle-east", "europe", etc.
        family?: string; // "national-id", "tax-id", "passport", etc.
        reference?: string; // URL to spec/standard
        examples?: string[]; // Valid synthetic examples (for docs + test gen)
      }

      examples is particularly interesting sinc we could generate tests and folks
      who add new examples get coverage for free. With a little rollup trickery
      (i.e. AST traversal or regex post-processing) we can remove this field during
      bundling too

    • Moving to describe.each and it.each on tests so we can go from:

      it("should detect UAE Emirates ID", async () => {
        const detector = new OpenRedaction({ patterns: ["UAE_EMIRATES_ID"] });
        const result = await detector.detect("Emirates ID: 784-1990-1234567-1");
        expect(result.detections.some((d) => d.type === "UAE_EMIRATES_ID")).toBe(
          true,
        );
      });
      
      it("should detect UAE Emirates ID without dashes", async () => {
        const detector = new OpenRedaction({ patterns: ["UAE_EMIRATES_ID"] });
        const result = await detector.detect("UAE ID 784199012345671");
        expect(result.detections.some((d) => d.type === "UAE_EMIRATES_ID")).toBe(
          true,
        );
      });

      to

      it.each(["UAE ID 784199012345671", "Emirates ID: 784-1990-1234567-1"])((str) => {
        const detector = new OpenRedaction({ patterns: ["UAE_EMIRATES_ID"] });
        const result = await detector.detect(str);
      
        expect(result.detections.some((d) => d.type === "UAE_EMIRATES_ID")).toBe(
          true,
        );
      });

      moreover, this could replace the existing build-regex-audit (which isn't run anywhere)

    • More cleanup of monolithic validators

    • Code split validates (one per country) for even smaller bundles

  3. sam247 commented on Jul 26, 2026

    @sam247
    OwnerAuthor

    That feels like a much better contributor experience than expecting people to understand the regex/validator stuff.

    The metadata idea also feels like it could become the single source of truth. If we have country/family/reference/examples available, we can generate a lot of things from that over time (tests, docs, coverage, contributor guidance, etc.) rather than maintaining them separately. I agree this is probably the right foundation before we start breaking this into lots of smaller help wanted issues. Happy to iterate on the shape of it as we go, but your direction feels far more sensible.

  4. BilliamBaSH commented on Nov 14, 2026

    @BilliamBaSH
    Contributor

    I've got two sets of made-up text that could help the false-positive side of this: 1) Technical text (UUIDs, hashes, timestamps, version strings)
    2) Everyday messages in 9 languages, all of which should stay quiet.

    Would fixtures like that be useful as a starting point? Happy to open a PR with whichever fits best.

  5. sam247 commented on Nov 14, 2026

    @sam247
    OwnerAuthor

    Thanks @BilliamBaSH, that would be brilliant!

    Both sets would be genuinely useful. I’d probably start with the technical fixtures, particularly UUIDs, hashes, timestamps and version strings, as we’ve already seen how easily those can trigger false positives.

    The multilingual everyday messages would also be a great follow-up.

    Ideally we’d keep these as reusable regression fixtures so future pattern changes can be tested against them.

    Happy for you to open a PR for the technical set first. Really appreciate you offering to help again!

  6. BilliamBaSH commented on Nov 15, 2026

    @BilliamBaSH
    Contributor

    Thanks @sam247!

    The technical set is up in #171. 396 made-up lines across UUIDs, hashes, timestamps and version strings, kept as regression fixtures like you said. 87 of them get flagged today, so those run as it.fails to keep CI green until they're fixed. I listed which shapes in the PR.

    I'll start on the multilingual set next as its own PR.

    Also, no worries on the extra help. It's really useful practice for me :D

  7. BilliamBaSH commented on Nov 26, 2026

    @BilliamBaSH
    Contributor

    Baseline from #171: 87 technical lines flagged today, pinned by a test so it can only go down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementhelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions