β‘ Zero-dependency, blazing-fast regex-based PII redaction with optional compliance dashboard integration.
Python package for redactpii.com - Protect PII before it hits AI APIs with optional SOC 2/HIPAA audit trails.
Built for the modern AI stack. Protect PII before it hits OpenAI, Anthropic, or LangChain with optional dashboard integration for SOC 2 & HIPAA audit trails.
- <1ms per operation - Optimized regex engine
- Zero external dependencies - Pure Python, no bloat
- Dashboard integration - SOC 2/HIPAA audit trails (optional)
- Zero-trust security - Never sends PII, only metadata
- Type hints - Full type safety and IDE support
- Python 3.8+
- Zero dependencies (seriously, check your requirements)
pip install redactpiifrom redactpii import Redactor
redactor = Redactor()
clean = redactor.redact('Hi David Johnson, call 555-555-5555')
# Result: "Hi PERSON_NAME, call PHONE_NUMBER"Enable optional dashboard integration for audit trails:
from redactpii import Redactor
import os
redactor = Redactor({
'api_key': os.getenv('REDACTPII_API_KEY'), # Enables compliance dashboard
'api_url': 'https://api.redactpii.com/v1/events', # Your audit endpoint (optional)
'rules': {
'CREDIT_CARD': True,
'EMAIL': True,
'NAME': True,
'PHONE': True,
'SSN': True,
},
})
clean = redactor.redact('CEO [email protected] called from 555-123-4567 with SSN 123-45-6789')
# Result: "CEO EMAIL_ADDRESS called from PHONE_NUMBER with SSN US_SOCIAL_SECURITY_NUMBER"
# π Zero-trust: Only metadata sent to dashboard
# π Audit log: {"sdk_version": "1.0.0", "pii_type": "EMAIL", "action": "REDACTED"}π Zero-Trust Guarantee: Never sends actual PII data. Only anonymized metadata for compliance reporting. Non-blocking requests with 500ms timeout - never impacts your app performance.
Built-in patterns for:
- π€ Names - Person identification (greeting-based detection)
- π§ Emails - Email addresses
- π Phones - US phone numbers (all formats)
- π³ Credit Cards - Visa, Mastercard, Amex, Diners Club
- π SSN - US Social Security Numbers
from redactpii import Redactor
redactor = Redactor({'rules': {'EMAIL': True}})
if redactor.has_pii('Contact [email protected] for details'):
print('PII detected!')
# Now redact it
clean = redactor.redact('Contact [email protected] for details')from redactpii import Redactor
redactor = Redactor({'rules': {'EMAIL': True}})
user = {
'name': 'John Doe',
'email': '[email protected]',
'profile': {
'contact': '[email protected]',
},
}
clean = redactor.redact_object(user)
# {
# 'name': 'John Doe',
# 'email': 'EMAIL_ADDRESS',
# 'profile': {
# 'contact': 'EMAIL_ADDRESS',
# },
# }Protect PII before it hits AI APIs. This is your compliance safety net.
Example: Using with OpenAI Client
from redactpii import Redactor
from openai import OpenAI
import os
redactor = Redactor({
'api_key': os.getenv('REDACTPII_API_KEY'),
'rules': {'SSN': True, 'EMAIL': True},
})
openai_client = OpenAI()
# 1. Redact the prompt BEFORE you send it
raw_prompt = 'My SSN is 123-45-6789 and my email is [email protected]'
safe_prompt = redactor.redact(raw_prompt)
# 2. Send the "safe" prompt to the LLM
completion = openai_client.chat.completions.create(
messages=[{'role': 'user', 'content': safe_prompt}],
model='gpt-4o',
)
# 3. Your audit log on redactpii.com now has proof
# of the redaction *before* it hit OpenAI.Example: Using with LangChain
from redactpii import Redactor
from langchain_openai import ChatOpenAI
import os
# 1. Init the redactor with your dashboard API key
redactor = Redactor({'api_key': os.getenv('REDACTPII_API_KEY')})
model = ChatOpenAI()
# 2. Create a middleware function to redact input
def redacting_middleware(input_data):
if redactor.has_pii(input_data['query']):
# Redact the input and log it to your dashboard
safe_query = redactor.redact(input_data['query'])
return {**input_data, 'query': safe_query}
return input_data
# 3. Use the middleware before sending to LLM
user_input = {'query': 'My email is [email protected]'}
safe_input = redacting_middleware(user_input)
result = model.invoke(safe_input['query'])
# Your prompt was safely redacted before hitting the LLM.redactor = Redactor({
'rules': {
'CREDIT_CARD': True, # Enable credit card detection
'EMAIL': True, # Enable email detection
'NAME': False, # Disable name detection
'PHONE': True, # Enable phone detection
'SSN': False, # Disable SSN detection
},
})import re
from redactpii import Redactor
redactor = Redactor({
'rules': {'EMAIL': True},
'custom_rules': [
re.compile(r'\b\d{5}\b'), # 5-digit codes
re.compile(r'\bSECRET-\d+\b'), # Secret codes
],
})redactor = Redactor({
'rules': {'EMAIL': True},
'global_replace_with': '[REDACTED]', # All PII types use this replacement
})
redactor.redact('[email protected]') # "[REDACTED]"redactor = Redactor({
'api_key': 'your-api-key',
'api_url': 'https://api.redactpii.com/v1/events', # Optional, defaults to this
'fail_silent': True, # Default: True (fail silently if dashboard is down)
'hook_timeout': 500, # Default: 500ms timeout for dashboard requests
'rules': {'EMAIL': True},
})Dashboard Payload:
{
"sdk_version": "1.0.0",
"sdk_language": "python",
"events": [
{ "pii_type": "EMAIL", "action": "REDACTED" },
{ "pii_type": "PHONE_NUMBER", "action": "REDACTED" }
]
}- Comprehensive tests covering all APIs and edge cases
- 100% type hints with mypy strict mode
- Zero unsafe operations - full type safety
- Pre-commit hooks - automatic linting and type checking
# Install dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=redactpii --cov-report=html
# Type checking
mypy redactpii
# Linting
ruff check redactpii testsWe welcome contributions! This library powers compliance for thousands of applications.
Built for the modern AI stack with optional SOC 2/HIPAA audit logs.