Skip to main content

scrubpii

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

pip install scrubpii
from scrubpii 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 scrubpii 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 scrubpii 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 scrubpii 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 scrubpii 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 "scrubpii[pandas]"

Keep personal data out of LLM prompts

from scrubpii 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 "scrubpii[server]"
scrubpii 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

scrubpii "Call Sarah at 662-634-1142"
cat notes.txt | scrubpii --mode mask > notes-redacted.txt
scrubpii --find "My SSN is 123-45-6789"
scrubpii --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 scrubpii 0.3.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 scrubpii 0.3.0
File Size Uploaded Provenance Actions
scrubpii-0.3.0.tar.gz 17.3 kB With provenance Details for scrubpii-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scrubpii 0.3.0
File Interpreter ABI Platform Actions
scrubpii-0.3.0-py3-none-any.whl Python 3 none any Details for scrubpii-0.3.0-py3-none-any.whl

Total release size: 33.8 kB

Release files / scrubpii-0.3.0.tar.gz

Download URL scrubpii-0.3.0.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4611afea3bb0c6dbbed41920357b174601fb6ae22dc3ec0465e6df6d2cd8ccd2
BLAKE2b-256 checksum
How to use checksums
e8c278eca34330d80345f08bd35ef4869b9e0e57cc8cd3251db9a326993a5e8d
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 / scrubpii-0.3.0-py3-none-any.whl

Download URL scrubpii-0.3.0-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e84c573c7bdcc7cf3fcfae2ec20902da358d4fd6d88bdaab11f55f98f2a4cdee
BLAKE2b-256 checksum
How to use checksums
a4b881fd4280448e096c7857ec227102c8a6f4db856dfa2ea969c8bbf26f14e7
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 scrubpii 0.3.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 scrubpii-0.3.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.3.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