localscrub
Local-first PHI/PII de-identification for clinical and free-form text.
Your data never leaves your machine: a fast rule/NER pass catches the obvious identifiers, and a local LLM handles the context-dependent remainder — no cloud APIs, no data crossing your trust boundary.
Status: v0.2 — usable, honest about its limits, pre-1.0 API. New here? Start with the quickstart. Roadmap: ROADMAP.md.
Why
Existing options force a bad trade:
- Cloud de-id APIs — accurate, but you send the sensitive data out to get it scrubbed.
- Local rule/NER tools — private, but miss context-dependent PHI in free text ("the patient's sister works at the bakery on Elm Street").
localscrub runs a two-stage cascade entirely on your hardware: cheap detection for the 90%+, a small fine-tuned local model for the ambiguous rest.
Usage
localscrub scrub notes.txt # print redacted text
localscrub scrub notes.txt --json # print the JSON entity report
localscrub scrub notes.txt -o clean.txt --report report.json
localscrub scrub --report-only < notes.txt # detect without rewriting
localscrub scrub notes.txt --fail-on-detect # CI gate: exit 3 if anything found
localscrub scrub notes.txt --llm # + stage 2: local LLM via Ollama
localscrub scrub notes.txt --ner # + pretrained clinical NER (CPU)
localscrub scrub notes.txt --ner --ner-backend onnx # same model, int8 ONNX: ~3x faster
localscrub scrub notes.txt --ner --ner-model OpenMed/OpenMed-PII-SuperClinical-Small-44M-v1 # 44M model, sharper names
localscrub synth -n 500 --seed 42 -o data/corpora/dev.jsonl # synthetic eval corpus
localscrub synth -n 500 --seed 42 --diversify -o dev.jsonl # + local-LLM paraphrase (Ollama)
localscrub mtsamples --fetch -n 100 --seed 42 -o mts.jsonl # injection benchmark: real prose
localscrub eval data/corpora/dev.jsonl # per-entity precision/recall
Current accuracy numbers (including what stage 1 honestly cannot catch yet)
live in docs/results.md. On our benchmark of authentic
medical-transcription prose, localscrub with the [ner] extra fully redacts
99.9% of planted identifiers on CPU, vs. 75% for Presidio, the
standard rules-only baseline — measured by the same harness, reproducible
locally: docs/benchmark.md.
Deploying on real clinical text? Read the trust-boundary and residual-risk discussion first: docs/threat-model.md.
Or from Python:
from localscrub import scrub
result = scrub("Reach the patient at test@example.com.")
result.redacted # 'Reach the patient at [EMAIL_1].'
result.entities # (Entity(type=EMAIL, start=21, end=37, confidence=0.95, ...),)
result.escalations # spans stage 1 couldn't settle — stage 2's work queue
Stage 1 (rules) currently detects: emails, phone/fax numbers, SSNs, credit
cards (Luhn-validated), IP addresses, URLs, dates and ages over 89, and
labeled MRN / health-plan / account identifiers. Uncertain or ambiguous spans
are redacted fail-closed and flagged for stage-2 adjudication. The [ner]
extra (pip install 'localscrub[ner]', then --ner) adds a pretrained
clinical NER model for person, facility, and employer names and places,
on CPU; [ner-onnx] with --ner-backend onnx runs the same model as an
int8 ONNX export, ~3× faster. Stage 2 (--llm, or
scrub(text, stage2=LlmExtractor())) runs a local Ollama model for
narrative identifiers and escalation adjudication; see
ADR 0002 for its contract.
Entity coverage
All 18 HIPAA Safe Harbor identifier categories (45 CFR 164.514(b)(2)), plus
generic PII that matters in practice: credit cards, passports, national IDs,
and leaked credentials/secrets. See src/localscrub/entities.py.
License
Apache-2.0 — see LICENSE.
Metadata
Release files for localscrub 0.2.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 |
|---|---|---|---|---|
| localscrub-0.2.0.tar.gz | 268.7 kB | Without provenance | Details for localscrub-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| localscrub-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for localscrub-0.2.0-py3-none-any.whl |
Total release size: 327.0 kB
Release files / localscrub-0.2.0.tar.gz
| Download URL | localscrub-0.2.0.tar.gz |
|---|---|
| Size | 268.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
52d9cbf7e239ee7a4f8bd96f9ede6d95c2e4454c7f530dcba79d142c334e2033
|
|
BLAKE2b-256 checksum How to use checksums |
ad4db3d3f3ebf04ffe5fbb417c2b19bc910db0c546a5c3387be2f88d93bd75f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / localscrub-0.2.0-py3-none-any.whl
| Download URL | localscrub-0.2.0-py3-none-any.whl |
|---|---|
| Size | 58.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1825ddff3488c7cc62b3cae9556df71a28facacced1765d3d081fd03aa292f35
|
|
BLAKE2b-256 checksum How to use checksums |
06f28c10d69853b3e3ec3ec7a473d372f0cf6638bcd5dbaeaf01f97e526251cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for localscrub 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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.