redactscope
redactscope

how redactscope fits in

Install

consolepip install redactscope

Use

pythonfrom redactscope import SecretLeak, assert_clean, audit, redact

clean = redact(tool_result)                 # a copy, never the original
findings = audit(tool_result)               # [Finding(path="metadata.api_key", kind="secret-key", …)]
assert_clean(tool_result)                   # raises SecretLeak, for a test or a gate

Wrapping a tool so nothing raw ever reaches the context:

pythondef safe_tool(function):
    def wrapper(*args, **kwargs):
        result = function(*args, **kwargs)
        findings = audit(result)
        if findings:
            log.warning("redacted %s", [str(finding) for finding in findings])
        return redact(result)
    return wrapper
console$ redactscope message.json > clean.json      # redacted JSON on stdout
$ redactscope trace.log                      # plain text works too
$ redactscope message.json --check           # exit 1 if anything was found
$ redactscope message.json --keys-only       # mask keys, leave other strings alone

What is caught

kind example
secret-keyany key whose name contains password, token, secret, api_key, authorization, credential, session, cookie, signature, …
openai-keysk-… (8+ characters after the prefix)
anthropic-keysk-ant-…
github-tokenghp_, gho_, ghu_, ghs_, ghr_, github_pat_
slack-tokenxoxb-, xoxp-, xoxa-, …
aws-access-keyAKIA… / ASIA… + 16 characters
google-api-keyAIza… + 35 characters
jwtthree dot-separated base64url segments starting eyJ
bearer / basic-authBearer …, Basic …
url-credentialspostgres://user:password@host
private-key-block-----BEGIN … PRIVATE KEY----- … -----END …

audit reports a path for each finding — messages[0].content, metadata.api_key — and a preview that never contains the value itself.

Rules

unlikely in prose (sk- needs 8 more characters, AKIA needs 16).

the value patterns, mask="[redacted]" to change the replacement.

the strings alone.

Limits

under an innocent key will pass — nothing pattern-based can fix that.

(token=abc123) is caught by its key, not by its value.

different false-positive budget.

Development

consolepython -m venv .venv
.venv/bin/pip install -e ".[test]"
.venv/bin/pytest

The suite covers every line of the package (pytest --cov --cov-branch), and the examples in the docstrings run as tests through --doctest-modules.

License

MIT.

Other libraries here

One problem each, standard library only, no runtime dependencies.