Lightning-fast, zero-overhead, 100% local Python utility to redact PII and secret API keys before external AI prompts, logs, or storage.
pip install sanitizai==0.1.0 Copy PIP instructions
In the era of Generative AI, passing unvetted user prompts, internal debug traces, or chat history to third-party LLM providers (OpenAI, Anthropic, Google Gemini, Groq, DeepSeek) introduces catastrophic privacy and security risks:
SanitizAI solves this with zero runtime dependencies. Built purely on Python's optimized native re engine, it sanitizes text in microseconds right on your local CPU.
SanitizAI automatically identifies and scrubs developer credentials across all top-tier generative AI platforms:
pip install sanitizai (Requires Python 3.10 or higher. Zero external runtime dependencies!)
import sanitizai raw_prompt = ( "User alice.smith@enterprise.com reported an issue. " "Her phone is 9876543210 and she used API key sk-proj-1234567890abcdef1234567890abcdef1234567890. " "Server IP was 192.168.1.50." ) clean_prompt = sanitizai.clean(raw_prompt) print(clean_prompt) Output:
User [EMAIL_REDACTED] reported an issue. Her phone is [PHONE_REDACTED] and she used API key [SECRET_KEY_REDACTED]. Server IP was [IP_ADDRESS_REDACTED]. 2. Selective Redaction (PII only or Secrets only) from sanitizai import redact_pii, redact_secrets # Redact only PII, keep technical keys intact: pii_safe = redact_pii("Contact me at dev@test.com with key sk-abc1234567890abcdef1234567890") # -> "Contact me at [EMAIL_REDACTED] with key sk-abc1234567890abcdef1234567890" # Redact only Secrets, keep user contact info: secret_safe = redact_secrets("Contact me at dev@test.com with key sk-abc1234567890abcdef1234567890") # -> "Contact me at dev@test.com with key [SECRET_KEY_REDACTED]" 3. Custom Blacklists & Custom Regex Patterns from sanitizai import SanitizAI sanitizer = SanitizAI( blacklist_words=["ProjectTitan", "AcmeInternal"], blacklist_replacement="[INTERNAL_CONFIDENTIAL]", custom_patterns={ r"TICKET-\d+": "[TICKET_REF]", } ) text = "Working on ProjectTitan for AcmeInternal. Reference TICKET-4912." print(sanitizer.clean(text)) # -> "Working on [INTERNAL_CONFIDENTIAL] for [INTERNAL_CONFIDENTIAL]. Reference [TICKET_REF]." 4. Non-Destructive Analysis (Inspection) Inspect text and count detected sensitive entities without modifying the original string:
from sanitizai import SanitizAI sanitizer = SanitizAI() stats = sanitizer.analyze("Call 555-123-4567 or email team@test.com with key sk-1234567890abcdef1234567890") print(stats) # -> {'openai_groq_anthropic_key': 1, 'email': 1, 'phone_intl': 1} 5. Large Stream Processing (Log Files / Generators) from sanitizai import SanitizAI sanitizer = SanitizAI() with open("massive_production.log", "r", encoding="utf-8") as infile, \ open("sanitized.log", "w", encoding="utf-8") as outfile: for clean_line in sanitizer.clean_stream(infile): outfile.write(clean_line) Command Line Interface (CLI) SanitizAI installs a standalone terminal executable sanitizai:
sanitizai "Contact support@example.com with key sk-1234567890abcdef1234567890" # Output: Contact [EMAIL_REDACTED] with key [SECRET_KEY_REDACTED] Standard Input (Unix Pipeline) # Pipe streaming logs directly tail -f access.log | sanitizai # Sanitize log file and redirect output cat server.log | sanitizai > sanitized.log File Input & Output sanitizai -i raw_records.txt -o clean_records.txt Display Redaction Statistics sanitizai --stats "Report: admin@bank.com accessed 10.0.0.1 with key sk-1234567890abcdef1234567890" Output:
Report: [EMAIL_REDACTED] accessed [IP_ADDRESS_REDACTED] with key [SECRET_KEY_REDACTED] --- SanitizAI Redaction Summary --- email: 1 ipv4: 1 openai_groq_anthropic_key: 1 Total Redactions: 3 ----------------------------------- Real-World Production Recipes Recipe 1: LLM Prompt Guard (OpenAI / Anthropic SDK) import os import sanitizai from openai import OpenAI client = OpenAI(api_key=os.environ["OPENAI_API_KEY"]) def query_llm_safely(raw_user_input: str) -> str: # 1. Sanitize user prompt locally before it leaves your server safe_prompt = sanitizai.clean(raw_user_input) # 2. Dispatch sanitized prompt to LLM response = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": safe_prompt}], ) return response.choices[0].message.content Recipe 2: Automatic Python Logging Filter import logging import sanitizai class SanitizingLogFilter(logging.Filter): def filter(self, record: logging.LogRecord) -> bool: if isinstance(record.msg, str): record.msg = sanitizai.clean(record.msg) return True logger = logging.getLogger("production") handler = logging.StreamHandler() handler.addFilter(SanitizingLogFilter()) logger.addHandler(handler) logger.setLevel(logging.INFO) # Will automatically mask PII & secrets in your logs! logger.info("Failed login for user john@doe.com with secret api_key='1234567890abcdef'") Performance & Benchmarks Toolkit Runtime Dependencies Cold Start Latency Throughput (lines/sec) SanitizAI 0 (Pure Python) < 1 ms ~60,000+ Heavy NLP / ML Toolkits PyTorch, Spacy, Transformers (~2.5 GB) ~1,500 - 4,000 ms ~800 Zero supply-chain vulnerability footprint, zero container bloat, microsecond latency.
# Clone the repository git clone https://github.com/sanitizai/sanitizai.git cd SanitizAI # Run tests with pytest python -m pytest tests/ -v Contributing We welcome community contributions, bug fixes, additional AI key formats, and performance enhancements!
SanitizAI is dedicated to providing a respectful, harassment-free, and inclusive experience for everyone. All participants are expected to adhere to our Code of Conduct (Contributor Covenant v2.1).
Security and vulnerability disclosures are handled with paramount urgency:
SanitizAI is distributed under the OSI-approved MIT License.
sanitizai pii redaction masking llm-guard prompt-security secrets api-keys privacy zero-dependency
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
The dropdown lists show the available interpreters, ABIs, and platforms.
Enable javascript to be able to filter the list of wheel files.
Copy a direct link to the current filters Copy
Details for the file sanitizai-0.1.0-py3-none-any.whl.




