UkPassportRecognizer matches no UK passport format (UK passport numbers are 9 digits)
Describe the bug
UkPassportRecognizer matches a format that UK passports do not use.
presidio_analyzer/predefined_recognizers/country_specific/uk/uk_passport_recognizer.py:
"""
UK passports issued from 2015 onwards use a 2-letter prefix
followed by 7 digits (e.g., AB1234567).
"""
PATTERNS = [
Pattern(
"UK Passport (weak)",
r"\b[A-Z]{2}\d{7}\b",
0.1,
),
]A UK passport number is 9 digits, all numeric, and has been for every series currently in circulation, including the 2015 series the docstring refers to. As a result the recognizer misses every real UK passport number, and matches strings of the form AB1234567 that are not UK passport numbers. The same claim appears on the supported entities page.
To Reproduce
presidio-analyzer 2.2.363 (the pattern is unchanged on main):
from presidio_analyzer.predefined_recognizers import UkPassportRecognizer
recognizer = UkPassportRecognizer()
for text in ["passport 123456789", "passport AB1234567"]:
results = recognizer.analyze(text, entities=["UK_PASSPORT"], nlp_artifacts=None)
print(f"{text!r}: {results}")Output:
'passport 123456789': []
'passport AB1234567': [type: UK_PASSPORT, start: 9, end: 18, score: 0.1]Expected behavior
A 9-digit UK passport number is detected, and AB1234567 is not. For example:
Pattern("UK Passport (weak)", r"\b\d{9}\b", 0.1)with the docstring and the supported-entities description corrected to match.
Additional context
- The pattern and docstring were introduced in #1862 and are unchanged on
main.
Sources:
HM Passport Office, the issuing authority: Basic passport checks (GOV.UK, updated 28 January 2026) describes the passport number for each series:
Series HM Passport Office 1988, 1998, 2006, 2010 "9 digits, printed on page 1" 2015 "9 digits, printed on page 1. These are entered on the biodata page (page 2) in the same style as the personal details" 2020 "9 numerical digits are: Printed on the inner front cover page" 2025 "9 numerical digits printed on the inner front cover" The only letter-bearing number the same guidance describes is the thin-film patch serial ("3 alpha characters and 4 numeric followed by a check symbol"), which it says "should not be confused with the 9 digit passport number".
NHS Data Dictionary, PASSPORT NUMBER (NEW): Format/Length "9 digits" (source: UK Government Data Standards Catalogue).
Microsoft Purview, U.S./U.K. passport number entity definition: Format "Nine digits". Purview has no two-letter-prefix form for UK passports.
Source: data-privacy-stack/presidio