Skip to content

feat(analyzer): add Danish CPR number recognizer#2196

Open
WMOlsen wants to merge 1 commit into
data-privacy-stack:mainfrom
WMOlsen:feature/dk-cpr-recognizer
Open

feat(analyzer): add Danish CPR number recognizer#2196
WMOlsen wants to merge 1 commit into
data-privacy-stack:mainfrom
WMOlsen:feature/dk-cpr-recognizer

Conversation

@WMOlsen

@WMOlsen WMOlsen commented Jul 24, 2026

Copy link
Copy Markdown

Change Description

Adds a Danish CPR number (DK_CPR_NUMBER) predefined recognizer to presidio-analyzer. Disabled by default in default_recognizers.yaml, tagged country_code: dk.

  • DK_CPR_NUMBER (DkCprRecognizer): the 10-digit Danish personnummer, format DDMMYY-SSSS (hyphenated) or DDMMYYSSSS (contiguous).
    • Date validation derives the full four-digit birth year from the official CPR century table (7th digit + two-digit year), so leap days are validated correctly (e.g. 290204 = 29 Feb 1904 is accepted, 290203 = 29 Feb 1903 is rejected).
    • Modulus-11 checksum (weights 4 3 2 7 6 5 4 3 2 1) is applied as confirmation only: a passing checksum promotes the match to full confidence, but a failing checksum never rejects the candidate. CPR-kontoret discontinued the mandatory modulus-11 control in 2007 because several birth dates had exhausted their supply of control-digit-valid sequence numbers, so numbers issued since then are not guaranteed to satisfy it. A hard checksum gate would silently drop valid personal data, which is the failure mode a PII detector must avoid.
    • Two \b-anchored patterns (hyphenated 0.5, contiguous 0.3); no boundary-less fallback, to avoid matching inside longer numeric strings.
  • Updated CHANGELOG.md, docs/supported_entities.md, default_recognizers.yaml, and predefined_recognizers/__init__.py.
  • Added tests/test_dk_cpr_recognizer.py; all cases pass locally. ruff check and ruff format --check pass on the changed files.

Known limitations: the contiguous 10-digit form can collide with other 10-digit numeric identifiers; this is mitigated by date validation, context words, and the lower 0.3 pattern score. Healthcare replacement numbers (erstatningsnumre, day + 60) are intentionally not matched, as they are a regional-system convention rather than CPR-register numbers. Space-separated forms (DDMMYY SSSS) are not matched.

Issue reference

N/A

Checklist

  • I have reviewed the contribution guidelines
  • I agree to follow this project's Code of Conduct
  • I confirm that I have the right to submit this contribution and that it does not knowingly contain proprietary or confidential code.
  • My code includes unit tests
  • All unit tests and lint checks pass locally
  • My PR contains documentation updates / additions if required

Add DkCprRecognizer for the 10-digit Danish personnummer (DK_CPR_NUMBER),
disabled by default and tagged country_code: dk.

Validation derives the full four-digit birth year from the official CPR
century table so leap days are handled correctly, and applies the modulus-11
checksum as confirmation only: a passing checksum promotes the match, a
failing one leaves the pattern score untouched. CPR-kontoret discontinued the
mandatory modulus-11 control in 2007, so numbers issued since then are not
guaranteed to satisfy it, and a hard checksum gate would drop valid numbers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant