Guardrails AI validator for African-specific PII — BVN, NIN, Ghana Card, KRA PIN, SA ID, and phone formats across NG, KE, ZA, GH, RW, EG.
Project description
guardrails-african-pii
Guardrails AI validator for African-specific PII detection.
Generic PII validators (Presidio, spaCy NER) have no awareness of African identity formats. This validator fills that gap with pattern-based detection aligned to each country's official format specifications.
Covered entities
| Entity | Jurisdiction | Format |
|---|---|---|
| BVN (Bank Verification Number) | Nigeria (NG) | Labelled 11-digit number |
| NIN (National Identity Number) | Nigeria (NG) | Labelled 11-digit number |
| CAC_RC_NUMBER (Corporate Registration) | Nigeria (NG) | RC + 4–7 digits |
| PHONE_NG | Nigeria (NG) | +234 / 0[789] prefix |
| KRA_PIN | Kenya (KE) | Letter + 9 digits + letter |
| NATIONAL_ID_KE | Kenya (KE) | Labelled 7–8 digit ID |
| PHONE_KE | Kenya (KE) | +254 / 0[71] prefix |
| NATIONAL_ID_ZA | South Africa (ZA) | Labelled 13-digit SA ID |
| SARS_TAX_REF | South Africa (ZA) | Labelled 10-digit tax ref |
| PHONE_ZA | South Africa (ZA) | +27 / 0 prefix |
| GHANA_CARD | Ghana (GH) | GHA-XXXXXXXXX-X |
| PHONE_GH | Ghana (GH) | +233 / 0[25] prefix |
| NATIONAL_ID_RW | Rwanda (RW) | Labelled 16-digit NID |
| PHONE_RW | Rwanda (RW) | +250 / 07 prefix |
| NATIONAL_ID_EG | Egypt (EG) | Labelled 14-digit national ID |
| PHONE_EG | Egypt (EG) | +20 / 01[0-5] prefix |
Regulatory alignment
- NDPA 2023 (Nigeria Data Protection Act) — §30 sensitive personal data
- KDPA 2019 (Kenya Data Protection Act) — §43 sensitive data
- POPIA (South Africa Protection of Personal Information Act) — §26
- Ghana Data Protection Act 2012
- Rwanda Law No. 058/2021 on personal data protection
- Egypt Data Protection Law No. 151/2020
Installation
guardrails hub install hub://guardrails/african_pii
Or install directly:
pip install guardrails-african-pii
Usage
from guardrails import Guard
from guardrails.hub import AfricanPii
# Detect all African PII
guard = Guard().use(AfricanPii, on_fail="exception")
guard.validate("Customer BVN: 12345678901")
# → raises ValidationError: African PII detected — BVN (NG)
# Auto-redact
guard_fix = Guard().use(AfricanPii, on_fail="fix")
result = guard_fix.validate("BVN: 12345678901 approved")
print(result.validated_output)
# → "[BVN] approved"
# Scope to specific jurisdictions
guard_ng_ke = Guard().use(
AfricanPii,
jurisdictions=["NG", "KE"],
on_fail="exception"
)
# Scope to specific entity types
guard_ids = Guard().use(
AfricanPii,
entities=["BVN", "GHANA_CARD", "KRA_PIN"],
on_fail="exception"
)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
entities |
list[str] | None |
None (all) |
Entity types to detect |
jurisdictions |
list[str] | None |
None (all) |
Country codes to check |
on_fail |
str | Callable |
— | Guardrails failure action |
When on_fail="fix", detected PII is replaced with [ENTITY_TYPE] placeholders.
Running tests
pip install guardrails-ai pytest
pytest tests/
Contributing
Part of a broader African compliance initiative. Issues and PRs welcome.
Built by Oluwajuwon Omotayo — also see:
- eve-policy — policy enforcement for AI agent tool calls
- guardrails-african-compliance — regulatory threshold and sensitive data validators
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file guardrails_african_pii-0.1.0.tar.gz.
File metadata
- Download URL: guardrails_african_pii-0.1.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a31803415e1c5bdf955bbfa8d79727b19f0337388a185210b0b88c82701e07bd
|
|
| MD5 |
ea2990839376245a499b4cd7dfa322c5
|
|
| BLAKE2b-256 |
4b701da4b933e88f4ea67ea44a4fef2f230bedc7cf5475452697998d662f0bb2
|
File details
Details for the file guardrails_african_pii-0.1.0-py3-none-any.whl.
File metadata
- Download URL: guardrails_african_pii-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f38ad686e867c5815582fcd280897aad406d6cf326fbfb4561619c082db02ebb
|
|
| MD5 |
268dd81fc14f9689823ad08a352e00d6
|
|
| BLAKE2b-256 |
c08638f4e0f6fcbd76476456fc3a4c45d402aba33d83298f48285893741d3c91
|