Metadata-Version: 2.4
Name: pii-scrubber-lite
Version: 0.1.0
Summary: Scrub PII from text before sending to LLMs. Detect and redact emails, phones, SSNs, credit cards, names, and more.
Author-email: Zach <zacharie@astera.org>
License: MIT
Project-URL: Homepage, https://github.com/zachbg/pii-scrub
Keywords: pii,redact,privacy,gdpr,llm,openai,scrub,anonymize
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Security
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# 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

```bash
pip install pii-scrub
```

## Quick Start

```python
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

```python
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

```python
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
