Python client for agent-sanitizer: a thin bridge to the Node.js CLI for byte-identical sanitization verdicts.
Actively maintained. Last release 8 days ago, commits in 21 of the last 26 weeks. A safe choice.
pip install agent-sanitizeragent-sanitizer (Python client)
A thin Python bridge to the agent-sanitizer
Node.js CLI. The sanitization logic has a single source of truth — the
JavaScript in src/ — so this package shells out to the CLI rather than
re-implementing it, giving a Python pipeline byte-identical verdicts with no
second implementation to keep in sync.
Requirements
- Node.js (>= 22) on
PATH. The sanitizer is JavaScript; something has to run it. There is deliberately no pure-Python fallback.
That's it — pip install agent-sanitizer and, with Node available, you're
ready to go. The wheel ships a self-contained, single-file build of the CLI
(the src/ logic and its npm dependencies bundled into one .mjs at release
time), so there is no separate JavaScript checkout to clone and no environment
variable to set. The bundle is a versioned build artifact from src/, not a
hand-maintained port, so it can't drift from the JS.
Optional: point at your own JS checkout
Set AGENT_SANITIZER_CLI to a checkout's bin/sanitize-cli.mjs to override the
bundled CLI (e.g. to run against unreleased src/ changes). When the module is
imported directly from a repo checkout, the source CLI is found automatically.
Usage
from agent_sanitizer import sanitize
result = sanitize("untrusted text", html=True)
print(result.cleaned, result.found, result.warnings)
See the package docstring for the full set of entry points (sanitize_text,
classify_prompt, scan_instruction_files, clean_file, and the long-lived
Sanitizer worker).
Secret redaction ([secrets] extra)
The base install is dependency-free. The optional secrets extra adds a
pure-Python secret-redaction engine under agent_sanitizer.secrets —
detect-secrets plus custom detectors, benign-value skipping, cross-line
reassembly, PEM collapse, and exact-match redaction of caller-supplied env-var
values. Unlike the sanitizer above it needs no Node.js; its only dependency
is detect-secrets, pulled in by the extra:
pip install "agent-sanitizer[secrets]"
Every detect-secrets import lives inside this subpackage, so a plain
import agent_sanitizer never touches it. The engine shares the parent
package's invisible-character SSOT () rather
than forking it — a fork would be a silent security regression.