Redact secrets and personal data from AI-agent transcripts, JSONL logs and text, without breaking their structure.
pip install redact-transcripts==0.1.0 Copy PIP instructions
This is a regex backstop, not a guarantee. It catches common credential shapes. It does not understand meaning. See What it misses before you rely on it.
$ pip install redact-transcripts $ redact-transcripts --version redact-transcripts 0.1.0 The examples below run from a checkout of this repository, and the test suite checks them (tests/test_readme.py). Redact a file to stdout, or to a new file with -o:
$ redact-transcripts examples/session.jsonl -o session.redacted.jsonl --report redact-transcripts: format=claude-code lines=4 changed=4 redacted=9 infra.ipv4 2 pii.email 1 pii.home_dir 4 secret.github_token 1 secret.url_credentials 1 For your own sessions, point it at ~/.claude/projects/ / .jsonl. Use it in a pipe (- reads stdin):
$ echo 'curl -H "Authorization: Bearer FAKE-EXAMPLE-0000-token" https://api.example.com' | redact-transcripts - curl -H "Authorization: Bearer [REDACTED:secret.bearer]" https://api.example.com Gate a commit or a CI job on it. --check writes nothing and exits 1 if a secret.* rule matches (--strict also fails on pii.* and infra.*):
$ redact-transcripts --check examples/session.jsonl || echo "secrets found" redact-transcripts: format=claude-code lines=4 changed=4 would redact=9 infra.ipv4 2 pii.email 1 pii.home_dir 4 secret.github_token 1 secret.url_credentials 1 secrets found A real example examples/session.jsonl is a short, synthetic Claude Code session in which the agent ran env and printed a token and a database URL. One of its lines:
{"type":"user","message":{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_01EXAMPLE","content":"GITHUB_TOKEN=ghp_FAKEEXAMPLE000000000000000000000000\nDATABASE_URL=postgres://app:FAKE-PASSWORD@203.0.113.10:5432/shop"}]}, "uuid":"…0003","parentUuid":"…0002", …} After redact-transcripts examples/session.jsonl:
from redact_transcripts import Redactor, StreamRedactor, redact_bytes, redact_text redact_text("export DB_PASSWORD=FAKE-hunter2") # 'export DB_PASSWORD=[REDACTED:secret.assignment]' with open("session.jsonl", "rb") as f: out, report = redact_bytes(f.read(), format="claude-code") # or "auto", "jsonl", "text" print(report.as_dict()["rules"]) # counts per rule, no values stream = StreamRedactor() # e.g. for a streamed model response for chunk in chunks: send(stream.feed(chunk)) # released line by line send(stream.close()) Rules redact-transcripts --list-rules prints them. Each match is replaced by [REDACTED: ].
Values that are clearly not secrets are left alone: ${VAR} and $VAR references, , ****, true/false/null, numbers except under a password, secret or PIN key, counters and metrics (tokensUsed: 12345, secretCount, password_attempts), and metadata keys such as max_tokens, tokenizer or password_policy.
Turn rules off with --disable NAME or a prefix (--disable pii), or in Python with Redactor(disable=["pii"]). An unknown name is an error. Add your own shapes:
$ redact-transcripts --rule 'secret.acme_token=\bacme_[A-Za-z0-9]{24,}' notes.txt from redact_transcripts import Config, Redactor, Rule, default_rules redactor = Redactor( rules=[*default_rules(), Rule.simple("secret.acme_token", r"\bacme_[A-Za-z0-9]{24,}")], config=Config(email_keep_domains=("example.com", "mycompany.example"), marker_template="‹{rule}›"), ) Formats --format Use for Structural fields (never rewritten) auto (default) picks one of the below from the first non-empty line claude-code Claude Code session transcripts sessionId, uuid, parentUuid, id, tool_use_id, timestamp, type, role, model, …, each only with its expected value shape jsonl any JSON Lines file none; --keep-key KEY keeps identifier-shaped values under KEY text logs, notes, anything else; streams from stdin n/a In the JSON formats both values and object keys are redacted, and a line that is not JSON is redacted as text. A raw private key pasted across several non-JSON lines is collected up to its END line.
from redact_transcripts import JsonlFormat, redact_bytes, register_format class MyTraces(JsonlFormat): def is_structural(self, key: str) -> bool: return key.endswith("_id") or key in {"span", "ts"} register_format(MyTraces(name="my-traces")) # now available by name out, report = redact_bytes(raw, format="my-traces") For a non-JSON format, subclass Format and implement redact_bytes(raw, redactor).
Known gaps, each pinned by a vector in vectors/known_misses.json:
It also has false positives on code: token = get_token() loses get_token, for example.
Performance: about 4–5 MB/s. The auto, jsonl and claude-code formats read the whole input into memory; --format text streams.
vectors/*.json holds the corpus the test suite runs: positive, negative (must stay byte-identical), split (chunk and line boundaries), encoded (JSON-escaped, \u escapes, base64) and known_misses. Every secret in it is synthetic and marked FAKE/EXAMPLE. The corpus is CC0, so copy it into any project. Format: vectors/README.md.
$ git clone && cd redact-transcripts $ python -m venv .venv && . .venv/bin/activate $ pip install -e '.[dev]' $ pytest # offline; also runs the vector corpus and doctests $ ruff check . && ruff format --check . && reuse lint Contributing Contributions are welcome under the Developer Certificate of Origin: sign off every commit (git commit -s). See CONTRIBUTING.md and SECURITY.md (how to report a missed secret shape).
Parts of this project were developed with AI assistance (Claude).
claude-code dlp jsonl privacy redaction secrets transcripts
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.




