Skip to content

Feature Request: Add Canadian postal code recognizer (CA_POSTAL_CODE) #2163

Description

@Joey239716

Is your feature request related to a problem? Please describe.

Presidio's Canadian coverage is currently limited to a single recognizer
(CA_SIN). Canadian postal codes are common PII in address data, forms, and
free text, but there is no predefined recognizer for them, so they go
undetected using the built-in recognizer set.

Describe the solution you'd like

I would like to contribute a Canadian postal code recognizer to
presidio-analyzer, following the conventions of the existing postal-code
recognizers already in the project.

Suggested first scope:

  • CA_POSTAL_CODE — a Canadian postal code
    in the standard A1A 1A1 format (Forward Sortation Area + Local Delivery Unit).
    • Similar postal-code recognizers already exist in Presidio, such as
      UK_POSTCODE and DE_PLZ, so this fits an established pattern.
    • UK_POSTCODE is the closest precedent: it is alphanumeric like Canada's and
      has no checksum, so detection relies on a tight regex plus context words.
    • Canada Post's format has clear public letter rules (the letters D, F, I, O,
      Q, U are never used, and W and Z are not used as the first letter), which
      keeps the regex specific and limits false positives.
    • Because the space between the FSA and LDU is often omitted in stored data, I
      plan to match both A1A 1A1 and A1A1A1, scoring the canonical spaced form
      higher — the same two-tier idea used by the existing CA_SIN recognizer for
      its delimited vs. undelimited forms.
    • Context words would be bilingual (English and French, e.g. "postal code" /
      "code postal"), since Canada is officially bilingual and CA_SIN already
      sets this precedent.

I also plan to update the relevant documentation as part of the contribution.

Describe alternatives you've considered

As of Presidio 2.2.363, the published recognizer set surfaces a few relevant
options:

  • A single pattern with an optional space at one confidence level, as
    UK_POSTCODE does. This is simpler, but it cannot score the canonical spaced
    form higher than the space-omitted form.
  • A user-defined custom PatternRecognizer. This works today, but a predefined
    recognizer benefits all Canadian users and keeps country coverage consistent.

Additional context

Format and letter-rule reference:
https://en.wikipedia.org/wiki/Postal_codes_in_Canada

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions