fix(analyzer): use valid region code GB instead of UK in PhoneRecognizer#2174
Merged
SharonHart merged 1 commit intoJul 21, 2026
Conversation
…ognizer
`PhoneRecognizer.DEFAULT_SUPPORTED_REGIONS` contained "UK", which is not a
valid region code in the phonenumbers library (Google libphonenumber). Region
codes are ISO 3166-1 alpha-2, where the United Kingdom is "GB"
(country_code_for_region("UK") == 0, and "UK" is not in
phonenumbers.SUPPORTED_REGIONS).
As a result the "UK" entry was a no-op: UK numbers written in national/local
format (e.g. "020 7946 0958") were never detected with the default
configuration. Only international-format "+44 ..." numbers matched, because
they carry the country code and match under any region.
Replaced "UK" with "GB" and added a regression test for a national-format
UK number.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a correctness gap in Presidio Analyzer’s PhoneRecognizer default configuration by switching the invalid libphonenumber region code "UK" to the valid ISO 3166-1 alpha-2 code "GB", restoring detection of UK national-format phone numbers under default settings.
Changes:
- Updated
PhoneRecognizer.DEFAULT_SUPPORTED_REGIONSfrom"UK"to"GB". - Added a regression test ensuring a UK national-format number (
020 7946 0958) is detected with defaults. - Documented the fix in the Analyzer “Fixed” section of
CHANGELOG.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| presidio-analyzer/presidio_analyzer/predefined_recognizers/generic/phone_recognizer.py | Replaces invalid default region "UK" with valid "GB" to enable UK national-format matching. |
| presidio-analyzer/tests/test_phone_recognizer.py | Adds a regression case proving UK national-format numbers are detected with the corrected default regions. |
| CHANGELOG.md | Records the behavior change/fix under [unreleased] → Analyzer → Fixed. |
SharonHart
approved these changes
Jul 21, 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.
Change Description
Fixes #2173.
PhoneRecognizer.DEFAULT_SUPPORTED_REGIONScontained"UK", which is not a valid region code in thephonenumberslibrary (Google libphonenumber). Region codes are ISO 3166-1 alpha-2, where the United Kingdom is"GB".Because
"UK"is not a real region, that entry was a no-op, and UK numbers in national/local format were never detected with the default configuration. Only international-format+44 …numbers matched — those carry the country code and match under any region, which is why the gap went unnoticed (the existing+44 (20) 7123 4567test passes for exactly this reason).Detection of a national-format UK number, before vs. after:
"UK")"GB")020 7946 0958(London landline)07911 123456(mobile)+44 7911 123456(international)Changes
phone_recognizer.py: replace"UK"with"GB"inDEFAULT_SUPPORTED_REGIONS.test_phone_recognizer.py: add a regression test for a national-format UK number (020 7946 0958).CHANGELOG.md: document the fix under[unreleased] → Analyzer → Fixed.How Has This Been Tested?
pytest tests/test_phone_recognizer.py— 27 passed (including the new case).ruff check presidio-analyzer/presidio_analyzer— all checks passed.Checklist