feat: Add CaPostalCodeRecognizer for Canadian postal codes (CA_POSTAL… - #2204
Merged
SharonHart merged 3 commits intoJul 29, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new predefined, Canada-specific analyzer recognizer to detect Canadian postal codes (CA_POSTAL_CODE) and wires it into Presidio’s predefined recognizer registry, with accompanying unit tests and documentation.
Changes:
- Introduces
CaPostalCodeRecognizerwith strict (spaced) and weak (unspaced) regex patterns plus context terms. - Registers the recognizer in the Canada package, the predefined recognizers package exports, and
default_recognizers.yaml(disabled by default). - Adds unit tests and documents the new
CA_POSTAL_CODEentity indocs/supported_entities.md.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/canada/ca_postal_code_recognizer.py | Implements CaPostalCodeRecognizer patterns/context and country tagging. |
| presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/canada/init.py | Exposes CaPostalCodeRecognizer from the Canada country-specific package. |
| presidio-analyzer/presidio_analyzer/predefined_recognizers/init.py | Exports CaPostalCodeRecognizer from the predefined recognizers package. |
| presidio-analyzer/presidio_analyzer/conf/default_recognizers.yaml | Adds the recognizer to the default registry configuration (disabled). |
| presidio-analyzer/tests/test_ca_postal_code_recognizer.py | Adds unit tests covering valid/invalid cases and boundary behavior. |
| docs/supported_entities.md | Documents the new CA_POSTAL_CODE supported entity. |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
presidio-analyzer/presidio_analyzer/predefined_recognizers/init.py:16
CaPostalCodeRecognizeris exported frompresidio_analyzer.predefined_recognizers, but the umbrella packagepresidio_analyzer.predefined_recognizers.country_specificstill only exportsCaSinRecognizer(seepredefined_recognizers/country_specific/__init__.py). If users rely onfrom presidio_analyzer.predefined_recognizers.country_specific import ..., this new recognizer won’t be available; consider updating that package’s__init__.py/__all__to includeCaPostalCodeRecognizeras well.
# Canada recognizers
from .country_specific.canada.ca_postal_code_recognizer import CaPostalCodeRecognizer
from .country_specific.canada.ca_sin_recognizer import CaSinRecognizer
SharonHart
approved these changes
Jul 29, 2026
This was referenced Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…_CODE)
Change Description
Adds a new predefined country-specific recognizer,
CaPostalCodeRecognizer, to detect Canadian postal codes in the standardA1A 1A1format (entity typeCA_POSTAL_CODE).Presidio has recognizers for other Canadian identifiers (
CaSinRecognizer) but no recognizer for postal codes, despite them being a common identifier in addresses, shipping records, and customer data.Details:
A1A 1A1format (letter-digit-letter, space, digit-letter-digit)K1A 0A1) scores 0.3; the space-omitted form (K1A0A1) scores 0.1, relying on surrounding context to clear the analyzer's score threshold, since the unspaced shape is more prone to coincidentally matching unrelated 6-character alphanumeric codesD,F,I,O,Q,Uare excluded from all letter positions;WandZare additionally excluded from the first letter position only (reserved for future expansion)PatternRecognizer's defaultIGNORECASEflag), since PII may appear in lowercase in real-world text even though Canada Post's official format is uppercasepostal code,code postal, province names), following the bilingual convention used byCaSinRecognizerenabled: false), matching the convention for other country-specific recognizersIssue reference
Fixes #2163
Checklist