Skip to main content

chad-pii

Find and redact personal data in text with one line of Python.

pip install chad-pii
from chad_pii import redact

redact("Hi, I'm Sarah Johnson. Email sarah.j@example.com or call 6626341142.")
# "Hi, I'm [PERSON]. Email [EMAIL] or call [PHONE]."

It finds names, addresses, emails, phone numbers, Social Security numbers, card numbers, IBANs, passports, driver's licenses, ID numbers, dates of birth, usernames, passwords, IP addresses and API keys, in English and Spanish. A fine-tuned DistilBERT model (ChadTollison/pii-distilbert-v3) does the finding, and rules double-check it: card numbers must pass Luhn, IBANs their bank checksum, SSNs the SSA format. The rules also catch what the model misses: Luhn-valid card numbers, SSNs, emails, IP addresses, US phone numbers with a real area code, valid IBANs, well-known API key formats and dates right after "born" or "DOB".

How it compares

F1 on held-out public data (full results in benchmarks/compare.md):

Dataset chad-pii Microsoft Presidio spaCy
ai4privacy, English 0.99 0.81 0.68
ai4privacy, Spanish 0.99 0.63 0.46
Gretel PII, English 0.99 0.85 0.36
Gretel finance (never trained on) 0.79 0.52 0.58

Presidio is about 4x faster per text.

The model (about 260 MB) downloads on first use and is cached, so after that it works offline. Nothing is sent anywhere.

Try it in your browser first: chadtollison.github.io/redact.html

Ways to redact

text = "Call Sarah Johnson at 662-634-1142."

redact(text)                # Call [PERSON] at [PHONE].
redact(text, mode="mask")   # Call █████████████ at ████████████.
redact(text, mode="fake")   # Call Avery Brooks at (202) 555-0117.

Fake values are harmless on purpose: phones use the 555-01xx range reserved for fiction, cards are public test numbers, IPs come from the documentation range, and SSNs start with 9, which is never issued.

Reversible tokens

from chad_pii import tokenize, restore

safe, key = tokenize(text)
# safe == "Call <PERSON_1> at <PHONE_1>."
# key  == {"<PERSON_1>": "Sarah Johnson", "<PHONE_1>": "662-634-1142"}

restore(safe, key)          # back to the original

Handy for sending text to another service (an LLM, a ticketing tool) and putting the real values back in its reply.

Just find

from chad_pii import find

for e in find(text):
    print(e.type, e.text, e.start, e.end, round(e.score, 2), e.rule)

min_score (default 0.5) sets how sure the model must be. Items caught or confirmed by a rule are always returned.

Many texts, JSON, CSV and pandas

Each of these batches the work, so it's much faster than a loop:

from chad_pii import redact_many, redact_json, redact_csv, redact_dataframe

redact_many(["Call Sarah at 6626341142", "Email raj@example.com"])

redact_json({"user": {"name": "Sarah Johnson", "email": "sarah.j@example.com", "age": 41}})
# {"user": {"name": "[PERSON]", "email": "[EMAIL]", "age": 41}}

redact_csv(open("customers.csv").read(), columns=["name", "email", "notes"])

safe_df = redact_dataframe(df, mode="fake")        # pip install "chad-pii[pandas]"

Keep personal data out of LLM prompts

from chad_pii import Guard

guard = Guard()
safe = guard.scrub("Write to Sarah Johnson (sarah.j@example.com) about her refund")
# "Write to <PERSON_1> (<EMAIL_1>) about her refund"   <- this is all the LLM sees
reply = call_your_llm(safe)                            # "Dear <PERSON_1>, ..."
guard.restore(reply)                                   # "Dear Sarah Johnson, ..."

ask = guard.wrap(call_your_llm)                        # or wrap the call once

The guard keeps one key for the whole conversation, so the same person stays <PERSON_1> in every turn. With LangChain: scrub, restore = guard.langchain() then chain = scrub | prompt | llm | parser | restore.

HTTP API

pip install "chad-pii[server]"
chad-pii serve --port 8000
curl -X POST localhost:8000/redact -H 'content-type: application/json' \
     -d '{"text": "Call Sarah at 6626341142", "mode": "token"}'

Endpoints: POST /redact, POST /find, POST /restore, GET /health, with interactive docs at /docs. It runs on your machine, so nothing is sent anywhere.

Command line

chad-pii "Call Sarah at 662-634-1142"
cat notes.txt | chad-pii --mode mask > notes-redacted.txt
chad-pii --find "My SSN is 123-45-6789"
chad-pii --file customers.csv --columns name,email -o customers-safe.csv   # also .json, .jsonl, .txt

Offline use

After the first run the model is cached, and nothing is ever sent anywhere. To be sure no network call is attempted, set HF_HUB_OFFLINE=1.

Limits

This is a research model. It can miss things or flag things by mistake, so please don't rely on it alone for compliance work.

MIT licensed. Made by Michael Chad Tollison.

Metadata

Release files for chad-pii 0.2.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 chad-pii 0.2.0
File Size Uploaded Provenance Actions
chad_pii-0.2.0.tar.gz 17.1 kB With provenance Details for chad_pii-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chad-pii 0.2.0
File Interpreter ABI Platform Actions
chad_pii-0.2.0-py3-none-any.whl Python 3 none any Details for chad_pii-0.2.0-py3-none-any.whl

Total release size: 33.6 kB

Release files / chad_pii-0.2.0.tar.gz

Download URL chad_pii-0.2.0.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2aa6514cd665f992ad0822e1eb385a76d958449394b53cf2e0e2c44b2898c771
BLAKE2b-256 checksum
How to use checksums
9475acc2d77811db321ae7d3bd31fcb951600818717c189467f0430712a565ab
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 27, 2026.

Transparency log

Release files / chad_pii-0.2.0-py3-none-any.whl

Download URL chad_pii-0.2.0-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0dad5ad072cf023875b66eaffab222b8791ca4c873d0800b60b87f32362d4f9
BLAKE2b-256 checksum
How to use checksums
66549de8b01325a9bbcd20c29d6e28ad4b225126b36708c1f478514ca5b0e9c4
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 27, 2026.

Transparency log

Security for chad-pii 0.2.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for chad_pii-0.2.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 27, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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