promptsanitizer
Secrets firewall for AI pipelines.
promptsanitizer helps redact, block, and audit sensitive data before it reaches an LLM — and before risky model outputs leave your application.
Why this exists
AI systems often pass user input, retrieved documents, tool outputs, and model responses through LLMs. That text can contain API keys, credentials, PII, or prompt injection attempts.
What it checks
- API keys, tokens, passwords, private keys, and cloud credentials
- PII such as emails, phone numbers, SSNs, credit cards, and IP addresses
- Prompt injection and jailbreak-style instructions
- Risky code execution patterns
- Exfiltration indicators such as internal URLs, metadata endpoints, and webhook-style payloads
Install
pip install promptsanitizer
Optional integrations:
pip install "promptsanitizer[openai]"
pip install "promptsanitizer[anthropic]"
pip install "promptsanitizer[all]"
Quick Start
from promptsanitizer import Firewall
fw = Firewall()
text = "My API key is sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
safe_text = fw.clean(text)
print(safe_text)
My API key is [REDACTED:openai_key]
Core features
- Inbound prompt scanning
- Outbound response scanning
- Redaction, blocking, and audit-only modes
- Default, strict, audit, and custom policies
- CLI support
- OpenAI and Anthropic middleware wrappers
- Compliance-style findings and reports
- Custom detection patterns
Findings privacy and history
Findings omit raw matched values by default. History retains the latest 1,000 findings;
use history_limit=0 to disable it, or set another limit for your application.
fw = Firewall(history_limit=100)
findings = fw.scan("email: dev@example.com")
print(findings[0].to_dict()) # Metadata only, without the matched email.
Strict mode blocks credentials and attack indicators, including generic API keys and exfiltration indicators. Scans preserve overlapping candidates so every blocking rule is evaluated. Private-key redaction covers complete blocks; an incomplete block is redacted through the end of the input.
See security behavior and migration notes for the policy matrix, raw-value opt-in, reporting semantics, and middleware coverage.
Who should use this
- AI engineers
- ML platform teams
- Security engineers
- Researchers
- Teams building agents, RAG systems, copilots, and AI assistants
Examples
Detailed examples are kept in the examples/ folder to keep this README simple.
examples/
basic_clean.py
strict_policy.py
custom_policy.py
prompt_injection_detection.py
outbound_response_scan.py
compliance_report.py
openai_middleware.py
anthropic_middleware.py
cli_scan.sh
cli_report.sh
CLI
promptsanitizer scan "email: dev@example.com"
promptsanitizer clean "my key is sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
promptsanitizer report --file prompt.txt
Where it fits
User input
-> promptsanitizer
-> LLM / agent / RAG pipeline
-> promptsanitizer
-> user / logs / downstream systems
Limitations
promptsanitizer is a defensive scanning layer, not a complete security boundary. Use it alongside access controls, secret management, logging controls, tool isolation, and output validation.
Metadata
Release files for promptsanitizer 1.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 |
|---|---|---|---|---|
| promptsanitizer-1.2.0.tar.gz | 21.4 kB | Without provenance | Details for promptsanitizer-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| promptsanitizer-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for promptsanitizer-1.2.0-py3-none-any.whl |
Total release size: 41.1 kB
Release files / promptsanitizer-1.2.0.tar.gz
| Download URL | promptsanitizer-1.2.0.tar.gz |
|---|---|
| Size | 21.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c38a8f59ee6c7835ebc3a3306b8049ba06f1ee0eb1b7ec8d858f1436bbc3f8c6
|
|
BLAKE2b-256 checksum How to use checksums |
83d4e38e919bee881717f2da84e5a94d2b3786d5de08017b87d87ca41b6ba861
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Release files / promptsanitizer-1.2.0-py3-none-any.whl
| Download URL | promptsanitizer-1.2.0-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
56fa5d7ec51713cf54ea6b3ced6cf5659feb1fa4e7f66b5cf4af9325d20ae58a
|
|
BLAKE2b-256 checksum How to use checksums |
2eac334aaa32d1d4a3fc7c2735b7bc528839bf58c6f70168eb27147f3644f017
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Security for promptsanitizer 1.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.