Skip to main content

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.

Hub License


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:

Release files for guardrails-african-pii 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for guardrails-african-pii 0.1.0
File Size Uploaded
guardrails_african_pii-0.1.0.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for guardrails-african-pii 0.1.0
File Interpreter ABI Platform
guardrails_african_pii-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.3 kB

Release files / guardrails_african_pii-0.1.0.tar.gz

Download URL guardrails_african_pii-0.1.0.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a31803415e1c5bdf955bbfa8d79727b19f0337388a185210b0b88c82701e07bd
BLAKE2b-256 checksum
How to use checksums
4b701da4b933e88f4ea67ea44a4fef2f230bedc7cf5475452697998d662f0bb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / guardrails_african_pii-0.1.0-py3-none-any.whl

Download URL guardrails_african_pii-0.1.0-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f38ad686e867c5815582fcd280897aad406d6cf326fbfb4561619c082db02ebb
BLAKE2b-256 checksum
How to use checksums
c08638f4e0f6fcbd76476456fc3a4c45d402aba33d83298f48285893741d3c91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page