Skip to content

feat: add NgBvnRecognizer (Nigerian BVN) and KeNationalIdRecognizer (Kenyan national ID)#2169

Open
kingztech2019 wants to merge 9 commits into
data-privacy-stack:mainfrom
kingztech2019:feat/african-pii-recognizers
Open

feat: add NgBvnRecognizer (Nigerian BVN) and KeNationalIdRecognizer (Kenyan national ID)#2169
kingztech2019 wants to merge 9 commits into
data-privacy-stack:mainfrom
kingztech2019:feat/african-pii-recognizers

Conversation

@kingztech2019

@kingztech2019 kingztech2019 commented Jul 18, 2026

Copy link
Copy Markdown

Change Description

Adds two new country-specific PII recognizers for African identifiers currently absent from Presidio:

NgBvnRecognizer — Nigerian Bank Verification Number (NG_BVN)

The BVN is an 11-digit identifier issued by the Central Bank of Nigeria (CBN) and managed by NIBSS (Nigerian Interbank Settlement System). It links every bank account held by an individual to a single biometric record. Unauthorized disclosure is a criminal offence under the CBN BVN Regulatory Framework (Circular FPR/DIR/GEN/CIR/01/009, 2014).

Design notes:

  • Pattern \b\d{11}\b at score 0.01 — same footprint as the existing NgNinRecognizer
  • BVN has no publicly documented checksum algorithm. validate_result returns None (not True) for structurally valid matches so context-boosted score is preserved rather than unconditionally promoting to MAX_SCORE
  • Context: bvn, bank verification number, bank verification no, nibss, bank identity number

KeNationalIdRecognizer — Kenyan National Identity Card (KE_NATIONAL_ID)

The Kenyan national ID card number is a 7–8-digit sequential identifier issued by the National Registration Bureau under the Registration of Persons Act (Cap. 107). Kenya currently has no recognizers in Presidio — this is the first.

Design notes:

  • Pattern \b\d{7,8}\b at score 0.01 — covers 7-digit (older cards) and 8-digit (current cards)
  • No checksum algorithm is publicly documented; validate_result returns None for structurally valid matches
  • Context: national id, national identity, nid, kenyan id, kenya national id, id card, national registration

Both recognizers are registered in default_recognizers.yaml with enabled: false.

Issue reference

N/A — new recognizer addition for uncovered African PII entities.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds two new country-specific Presidio Analyzer recognizers to cover currently-missing African identifiers: Nigerian BVN (NG_BVN) and Kenyan National ID (KE_NATIONAL_ID). This extends the predefined recognizer catalog and makes the new recognizers configurable via the default registry YAML (disabled by default).

Changes:

  • Added NgBvnRecognizer (Nigeria) with a very-weak 11-digit pattern and context-driven scoring (no checksum).
  • Added KeNationalIdRecognizer (Kenya) with a very-weak 7–8 digit pattern and context-driven scoring (no checksum).
  • Registered both recognizers in presidio_analyzer/conf/default_recognizers.yaml and exported them via presidio_analyzer/predefined_recognizers/__init__.py.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
presidio-analyzer/tests/test_ng_bvn_recognizer.py Adds unit tests for BVN detection and validation behavior.
presidio-analyzer/tests/test_ke_national_id_recognizer.py Adds unit tests for Kenyan National ID detection and validation behavior.
presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/nigeria/ng_bvn_recognizer.py Introduces the new Nigerian BVN recognizer implementation.
presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/nigeria/init.py Exposes NgBvnRecognizer from the Nigeria recognizers package.
presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/kenya/ke_national_id_recognizer.py Introduces the new Kenyan National ID recognizer implementation.
presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/kenya/init.py Creates the Kenya recognizers package and exports KeNationalIdRecognizer.
presidio-analyzer/presidio_analyzer/predefined_recognizers/init.py Exports the two new recognizers via the predefined recognizers module.
presidio-analyzer/presidio_analyzer/conf/default_recognizers.yaml Registers the new recognizers (disabled by default) with country metadata.

Comment on lines +1 to +4
import pytest

from presidio_analyzer.predefined_recognizers import NgBvnRecognizer
from tests.assertions import assert_result_within_score_range
Comment on lines +109 to +125
def test_when_bvn_in_text_then_expected_results(
text,
expected_len,
expected_positions,
expected_score_ranges,
recognizer,
entities,
):
results = recognizer.analyze(text, entities)
assert len(results) == expected_len

for res, (st_pos, fn_pos), (st_score, fn_score) in zip(
results, expected_positions, expected_score_ranges
):
assert_result_within_score_range(
res, entities[0], st_pos, fn_pos, st_score, fn_score
)
Comment on lines +55 to +60
(
f"bank verification number: {VALID_BVN_2}",
1,
((26, 37),),
((0.3, 1.0),),
),
Comment on lines +40 to +51
CONTEXT = [
"national id",
"national identity",
"national identity card",
"id number",
"nid",
"kenyan id",
"kenya national id",
"registration number",
"id card",
"national registration",
]
Comment on lines +1 to +4
import pytest

from presidio_analyzer.predefined_recognizers import KeNationalIdRecognizer
from tests.assertions import assert_result_within_score_range
Comment on lines +107 to +124
def test_when_ke_national_id_in_text_then_expected_results(
text,
expected_len,
expected_positions,
expected_score_ranges,
recognizer,
entities,
):
results = recognizer.analyze(text, entities)
assert len(results) == expected_len

for res, (st_pos, fn_pos), (st_score, fn_score) in zip(
results, expected_positions, expected_score_ranges
):
assert_result_within_score_range(
res, entities[0], st_pos, fn_pos, st_score, fn_score
)

Comment on lines +43 to +48
(
f"national id: {VALID_ID_8}",
1,
((13, 21),),
((0.3, 1.0),),
),
Comment on lines +61 to +66
(
f"national identity card: {VALID_ID_8}",
1,
((23, 31),),
((0.3, 1.0),),
),
Comment on lines +184 to +189
- name: NgBvnRecognizer
supported_languages:
- en
type: predefined
enabled: false
country_code: ng
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.

3 participants