Skip to main content

pii-scrub

Scrub PII from text before sending to LLMs. Detect and redact emails, phone numbers, SSNs, credit cards, IP addresses, and more. Zero dependencies. GDPR/HIPAA friendly.

The Pain

You're sending customer data to OpenAI and your compliance team is panicking. Names, emails, SSNs, and credit card numbers are leaking to third-party AI providers.

Install

pip install pii-scrub

Quick Start

from pii_scrub import scrub, detect

text = "Contact John Smith at john@example.com or 555-123-4567. SSN: 123-45-6789"

# Scrub all PII
clean = scrub(text)
print(clean)
# "Contact [NAME] at [EMAIL] or [PHONE]. SSN: [SSN]"

# Detect without scrubbing
findings = detect(text)
for f in findings:
    print(f"{f.type}: '{f.text}' at position {f.start}-{f.end}")
# EMAIL: 'john@example.com' at position 26-42
# PHONE: '555-123-4567' at position 46-58
# SSN: '123-45-6789' at position 65-76

What It Detects

PII Type Examples
Email user@example.com
Phone (555) 123-4567, +1-555-123-4567, 555.123.4567
SSN 123-45-6789, 123 45 6789
Credit Card 4111-1111-1111-1111, 5500 0000 0000 0004
IP Address 192.168.1.1, 10.0.0.1
Date of Birth born 01/15/1990, DOB: 1990-01-15
Street Address 123 Main Street, Apt 4B
Passport Passport: AB1234567
Driver License DL: D1234567
Bank Account Account: 1234567890
API Key sk-proj-xxx, Bearer xxx

API

from pii_scrub import scrub, detect, scrub_dict

# Scrub text (returns cleaned string)
clean = scrub(text, types=None, placeholder="[{type}]")

# Custom placeholders
clean = scrub(text, placeholder="***")  # all replaced with ***
clean = scrub(text, placeholder="[REDACTED]")

# Detect only (returns list of Finding objects)
findings = detect(text, types=["EMAIL", "PHONE"])  # specific types only

# Scrub nested dicts/lists (for JSON payloads)
data = {"user": {"name": "John", "email": "john@test.com"}, "msg": "Call 555-1234"}
clean_data = scrub_dict(data)
# {"user": {"name": "John", "email": "[EMAIL]"}, "msg": "Call [PHONE]"}

OpenAI Integration

from pii_scrub import scrub
import openai

def safe_completion(messages):
    # Scrub PII from all messages before sending
    clean_messages = [
        {**m, "content": scrub(m["content"])} for m in messages
    ]
    return openai.chat.completions.create(
        model="gpt-4o", messages=clean_messages
    )

Features

  • Zero dependencies — pure Python regex-based detection
  • Fast — <1ms for typical inputs
  • 11 PII types — email, phone, SSN, credit card, IP, DOB, address, passport, DL, bank, API keys
  • Custom placeholders — [EMAIL], ***, [REDACTED], or any format
  • Dict/JSON support — recursively scrub nested data structures
  • Type filtering — detect/scrub only specific PII types
  • Position tracking — know exactly where PII was found

License

MIT

Metadata

Release files for pii-scrubber-lite 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 pii-scrubber-lite 0.1.0
File Size Uploaded Provenance
pii_scrubber_lite-0.1.0.tar.gz 5.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pii-scrubber-lite 0.1.0
File Interpreter ABI Platform
pii_scrubber_lite-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / pii_scrubber_lite-0.1.0.tar.gz

Download URL pii_scrubber_lite-0.1.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
cfad8f1105b6b40e82ecfbbbf53fb01b4a47275c68b8b65a454c3daa25ea9bf2
BLAKE2b-256 checksum
How to use checksums
1cb4dc1a9ea4bcb5bb618ca680dad656b334a3898ffab202d4e6d480d3b92578
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

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

Download URL pii_scrubber_lite-0.1.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dea6bc5e3ae02f63734afb88f87e1b5991116a07ece1cd86a2f1aae2cccf3776
BLAKE2b-256 checksum
How to use checksums
4ccadfd3cf247800c6f2bfbd7b8b17145a29fb2e6cc897fc83eacc5dfe456aa9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Security for pii-scrubber-lite 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.

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No 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