feat(analyzer): add generic VIN and IMEI recognizers#2070
feat(analyzer): add generic VIN and IMEI recognizers#2070thatomokoena wants to merge 11 commits into
Conversation
Add VinRecognizer and ImeiRecognizer as enabled predefined recognizers with pattern matching, context support, and checksum validation for vehicle and mobile device identifiers. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds two new generic predefined recognizers (VIN and IMEI) to Presidio Analyzer and wires them into the default registry/config, along with tests and documentation updates.
Changes:
- Introduces
VinRecognizerwith a VIN regex plus check-digit validation logic. - Introduces
ImeiRecognizerwith IMEI regex patterns plus Luhn checksum invalidation. - Registers both recognizers in package exports, default YAML config, supported entities docs, and changelog.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| presidio-analyzer/presidio_analyzer/predefined_recognizers/generic/vin_recognizer.py | New VIN recognizer implementation with mod-11 check digit logic |
| presidio-analyzer/presidio_analyzer/predefined_recognizers/generic/imei_recognizer.py | New IMEI recognizer implementation with Luhn validation |
| presidio-analyzer/presidio_analyzer/predefined_recognizers/generic/init.py | Exposes new recognizers from the generic package |
| presidio-analyzer/presidio_analyzer/predefined_recognizers/init.py | Exposes new recognizers at the top-level predefined module |
| presidio-analyzer/presidio_analyzer/conf/default_recognizers.yaml | Enables loading the new recognizers by default |
| presidio-analyzer/tests/test_vin_recognizer.py | Adds unit tests for VIN detection and validation behavior |
| presidio-analyzer/tests/test_imei_recognizer.py | Adds unit tests for IMEI detection and invalidation behavior |
| docs/supported_entities.md | Documents newly supported IMEI and VIN entities |
| CHANGELOG.md | Records the addition of VIN and IMEI recognizers |
Reject invalid North American VIN check digits for WMI prefixes 1-5 while preserving base scores for non-NA VINs. Remove bare 15-digit IMEI pattern to avoid collisions with AMEX and other Luhn identifiers. Co-authored-by: Cursor <cursoragent@cursor.com>
Wire sanitize_value through invalidate_result so custom separator replacement_pairs are honored, matching other pattern recognizers. Co-authored-by: Cursor <cursoragent@cursor.com>
Align IMEI Luhn description and VIN validate_result return docs with actual behavior per Copilot review feedback. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Hi @SharonHart @omri374. When you have time, would you be willing to take a look at this PR for adding IMEI and VIN recognizers? Happy to address any feedback. Thanks! |
Reflect two new enabled predefined recognizers in the registry test assertion. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Hi @SharonHart. The CI failure on PR #2070 is fixed. The CI should be green on the next run. When you have a moment, could you take another look? Thanks! |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…rivacy-stack#2070 Document space-delimited IMEI formats in the changelog and add ImeiRecognizer and VinRecognizer to PREDEFINED_RECOGNIZERS so default engine tests cover the new recognizers. Co-authored-by: Cursor <cursoragent@cursor.com>
| ("Vehicle VIN is 1HGCM82633A004352", 1, ((15, 32),), ((0.5, "max"),)), | ||
| ("chassis number 1HGCM82633A004352 recorded", 1, ((15, 32),), ((0.5, "max"),)), | ||
| ("vin: 1hgcm82633a004352", 1, ((5, 22),), ((0.5, "max"),)), | ||
| ("The vehicle identification number is 1HGCM82633A004352", 1, ((37, 54),), ((0.5, "max"),)), |
| if fn_score == "max": | ||
| fn_score = max_score | ||
| assert_result_within_score_range( |
omri374
left a comment
There was a problem hiding this comment.
Thanks and apologies for the late review! Left a couple of comments. Happy to hear your thoughts on the VIM logic and its robustness
| type: predefined | ||
|
|
||
| - name: VinRecognizer | ||
| type: predefined |
There was a problem hiding this comment.
VIN should be disabled by default. Unlike IMEI (delimiters + Luhn make coincidental matches essentially impossible), VinRecognizer uses a bare pattern at 0.5, and its checksum can't compensate: the mod-11 check digit is only mandated in North America (49 CFR 565 / China GB 16735), not by ISO 3779. So validate_result returns None (keeping 0.5) for any non-NA token with a bad check digit, and True (→ MAX 1.0) for the ~1/11 of random 17-char tokens that coincidentally match. That means order IDs, tracking numbers, hex/base32 substrings and SKUs surface for every user by default. Every other checksum-preserving recognizer that uses this None-on-mismatch idiom (de_vat_id, uk_driving_licence, uk_vehicle_registration, kr_rrn, …) is a country recognizer disabled by default.
Please add enabled: false here (or gate detection on a context word). IMEI is fine to keep enabled.
| "text, expected_len, expected_positions, expected_score_ranges", | ||
| [ | ||
| # fmt: off | ||
| ("Vehicle VIN is 1HGCM82633A004352", 1, ((15, 32),), ((0.5, "max"),)), |
There was a problem hiding this comment.
These valid-VIN cases assert the score range (0.5, "max"), so if the MAX-promotion in validate_result ever broke, the tests would still pass. Assert exact MAX for verified NA VINs instead.
More importantly, please add a negative case proving a random 17-char non-VIN token (e.g. a 17-char order ID/hex string with no I/O/Q) is not flagged. That's the actual false-positive surface and a context-scoring test, since no test currently exercises context enhancement.
Change Description
VinRecognizerforVIN(17-character ISO 3779 vehicle identifiers) with pattern matching, context words, and North American mod-11 check-digit validation. Valid check digits boost confidence toMAX_SCOREfor any region; invalid check digits are rejected for North American WMIs (prefix 1-5); non-NA mismatches keep the base pattern score.ImeiRecognizerforIMEI(15-digit mobile device identifiers) with a formatted pattern (##-######-######-#), context words, and Luhn checksum invalidation. Bare 15-digit matching is omitted to avoid collisions with other Luhn identifiers such as AMEX credit card numbers.default_recognizers.yaml(enabled by default), exports them frompredefined_recognizers, and documents them insupported_entities.mdandCHANGELOG.md.test_vin_recognizer.pyandtest_imei_recognizer.py; all pass locally.ruff checkpasses on new recognizer source files.Issue reference
N/A
Checklist