bharatid
Detect, validate and redact Indian identifiers in text. Zero dependencies, pure Python 3.9+. Built for LLM guardrails, log scrubbing and data-loss prevention, where a bare regex for "12 digits" or "5 letters, 4 digits, 1 letter" flags far too much.
| Identifier | Check | Notes |
|---|---|---|
| Aadhaar | Verhoeff checksum + first digit 2-9 | rejects ~90% of random 12-digit numbers |
| GSTIN | Base-36 checksum + valid state code + valid embedded PAN | beats the PAN inside it when both match |
| PAN | structure (4th letter = entity type) | no public checksum |
| TAN, IFSC, EPIC (voter ID), passport | structure | IFSC bank/branch not looked up |
| Driving licence | structure + RTO state code + year 1950-2035 | |
| Vehicle plate | structure + RTO state code (incl. Bharat series) | |
| UPI ID | handle@psp with a known PSP handle |
ordinary emails are not matched |
| Mobile | 10 digits starting 6-9, optional +91 / 0 | |
| PIN code, bank account | only with a cue word ("PIN code", "A/c no") | bare 6- or 12-digit numbers are ignored |
Related project: the PyPI package indic-pii (by a different author) also detects Indian PII, with
confidence scores and optional spaCy NER for names. bharatid is a different design: zero
dependencies, checksum-first validation (Aadhaar, GSTIN), and extra identifiers (GSTIN, TAN, vehicle
plates). Pick whichever fits; they are not drop-in compatible.
"Valid" means well-formed (and checksum-correct where a checksum exists). It does not mean the number was issued to anyone.
Install and use
pip install bharatid
from bharatid import scan, redact, is_valid_aadhaar, is_valid_gstin
text = "Aadhaar 2345 6789 0124, PAN ABCPD1234E, call +91 98765 43210"
for m in scan(text):
print(m.type, m.text, m.validated) # validated=True when a checksum confirmed it
redact(text) # 'Aadhaar [AADHAAR], PAN [PAN], call [MOBILE]'
redact(text, types=["aadhaar"])
is_valid_gstin("27AAPFU0939F1ZV") # True
CLI: echo "PAN ABCPD1234E" | bharatid scan (exit code 1 when something is found), bharatid redact FILE.
How well does it avoid false alarms?
On 15,140 real, mostly English LLM prompts (public in-the-wild jailbreak dataset, MIT licence), it
produced 10 matches in total (8 mobile, 1 voter-ID-shaped, 1 Aadhaar-valid). The data has no PII labels,
so this is a false-alarm sanity check, not a precision measurement. Reproduce with
scripts/fp_sanity.py.
Limits
- Format and checksum validation cannot tell a real identifier from a coincidentally valid one.
- Mobile-number and voter-ID shapes are common in unrelated text.
- No names, addresses or free-text detection. Pair it with an NER tool if you need those.
- Not legal advice or a compliance guarantee. Test on your own data.
Related projects
- guardkit: offline guardrails for LLM apps (PII, secrets, injection), with its own smaller PII guard and a PyPI release.
- injection-bench: benchmark harness for prompt-injection detectors.
MIT licensed.
Metadata
Release files for bharatid 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bharatid-0.1.0.tar.gz | 8.8 kB | With provenance | Details for bharatid-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bharatid-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for bharatid-0.1.0-py3-none-any.whl |
Total release size: 17.4 kB
Release files / bharatid-0.1.0.tar.gz
| Download URL | bharatid-0.1.0.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
504e721a79d608edc3d6809b9cb2ffbc1cac0fb3d9f965386817b14bfb311ab6
|
|
BLAKE2b-256 checksum How to use checksums |
82d0b36baef77a37bb55be0624430564e6573abc3d73ba45624fd4eee6a013be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logRelease files / bharatid-0.1.0-py3-none-any.whl
| Download URL | bharatid-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a9f5af7407d279fa801f570920e9c4f53f446857c8a998ce00b2d27daf9ad401
|
|
BLAKE2b-256 checksum How to use checksums |
a93bd06ba21c3e18b34d1843354f538ae4b9e8f9c2e364700e6389c112802807
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logSecurity for bharatid 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for bharatid-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.