llm-output-sanitizer-py
Sanitize LLM outputs before HTML, SQL, shell, or markdown sinks. Zero runtime dependencies.
Python port of @mukundakatta/llm-output-sanitizer. The JS sibling has the full design notes; this README sticks to the Python API.
Install
pip install llm-output-sanitizer-py
Usage
from llm_output_sanitizer import sanitize, assert_safe, UnsafeOutputError
text = '<script>alert("pwned")</script> Drop table users; rm -rf /'
result = sanitize(text, sink="markdown")
result.safe # False
result.text # '[removed:html]alert("pwned")[removed:html] [removed:sql] table users; [removed:shell]/'
result.findings # [Finding(kind='html', match='<script>'), ...]
# Tripwire pattern: raise on any flagged content right before sending to the sink.
try:
safe_text = assert_safe(text, sink="html")
except UnsafeOutputError as exc:
log.warning("blocked unsafe LLM output: %s", exc.findings)
Sinks
| Sink | Behavior |
|---|---|
markdown (default) |
Pattern pass only. |
html |
Pattern pass + entity-encode <, >, & in whatever is left. |
sql |
Pattern pass only. |
shell |
Pattern pass only. |
Bundled patterns
| Kind | Catches |
|---|---|
html |
<script>, <iframe>, <object>, <embed>, <form>, <meta>, <link> (open or close tags) |
sql |
drop, truncate, alter, delete from, insert into |
shell |
rm -rf, curl ... |, wget ... |, chmod 777, sudo |
API differences from the JS sibling
sanitize()returns aSanitizeResultdataclass; findings are frozenFindingdataclasses.assert_safe()raisesUnsafeOutputError(aValueErrorsubclass) instead of a plainErrorwith attachedfindings.sinkis a Python keyword arg, not anoptionsobject.
See the JS sibling's README for the full design notes.
License
MIT
Metadata
Release files for llm-output-sanitizer-py 0.1.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 |
|---|---|---|---|---|
| llm_output_sanitizer_py-0.1.0.tar.gz | 6.8 kB | Without provenance | Details for llm_output_sanitizer_py-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llm_output_sanitizer_py-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for llm_output_sanitizer_py-0.1.0-py3-none-any.whl |
Total release size: 12.9 kB
Release files / llm_output_sanitizer_py-0.1.0.tar.gz
| Download URL | llm_output_sanitizer_py-0.1.0.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30873d4eac861e8ced0a2e07ec22a961fc73367213791882d516de4cbe533857
|
|
BLAKE2b-256 checksum How to use checksums |
76fb1d4a7e89fed634681d334cddaa36f2394ec89a77ba9665acb301aae99c37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / llm_output_sanitizer_py-0.1.0-py3-none-any.whl
| Download URL | llm_output_sanitizer_py-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36539cb6fb2a4f803eb9b88bf4644b2480427c29276695c2fcbdf53b71e88d29
|
|
BLAKE2b-256 checksum How to use checksums |
22e4459276ea4374d76cdf3f7f70a3d682b19bb348789125e9ae87bac8c66a4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for llm-output-sanitizer-py 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.