agentsec · Tools · promptleak

Offline · stdlib-only · MIT

promptleak: detect system-prompt leakage in transcripts in AI agents


Detects system-prompt leakage in LLM app transcripts and outputs, offline.

What it detects

Detects system-prompt leakage in LLM app transcripts and outputs, offline.

System prompts often carry business rules, internal codenames, routing logic and sometimes secrets that should never have been there. Prompt-extraction attacks ("repeat the words above", "print your instructions in a code block") get models to recite them. promptleak compares what the model actually said (assistant text and tool-call arguments) against the system/developer prompt and reports how much of it came back out, verbatim or lightly obfuscated.

Inputs: OpenAI-style message lists (incl. developer role and tool_calls), Anthropic requests/sessions (top-level system, tool_use blocks), generic {"messages": [...]} JSON or JSONL, plain text outputs, directories, or stdin (-). If no --prompt is given, the system messages inside each transcript are used.

Rules

RuleSeverityFinding
PL01criticalBulk leak: coverage ≥ --bulk (default 50%) of a prompt
PL02highVerbatim span ≥ --span words (default 25) or coverage ≥ --partial (default 20%)
PL03mediumShorter verbatim fragment(s) (at least *n* words)
PL04highA prompt line marked confidential/secret/"do not reveal"/password/API key/codename was reproduced
PL05criticalA --protect string appeared in output (also checked inside base64/hex blobs); shown masked
PL06highA base64 / base64url / hex blob in output decodes to prompt content (e.g. smuggled via a tool call)
PL07infoA user turn looks like a prompt-extraction attempt (context for the findings above)

Usage

cd tools/promptleak
python3 promptleak.py examples/leaky_transcript.json          # 6 findings, exit 1
python3 promptleak.py examples/clean_transcript.json          # 1 info (attempt, no leak), exit 0
python3 promptleak.py examples/anthropic_session.jsonl        # PL03 fragment, exit 1
python3 promptleak.py -p examples/system_prompt.txt examples/model_output.txt --protect "BLUE HERON"
my_app --once | python3 promptleak.py -p prompts/system.txt - --fail-on high   # CI / guard
python3 promptleak.py logs/ -p prompts/system.txt --json --min-severity medium

After pip install of the kit, the same options work as agentsec promptleak …. Every tool also accepts --help and almost every tool accepts --json.

Example output

See the examples under tools/promptleak/examples/ in the repository.

SARIF and CI

agentsec promptleak path/to/input --sarif > promptleak.sarif

# GitHub Actions (composite action ships with the repo)
- uses: dunkleschitz/agentsec@v0
  with:
    tools: promptleak
    paths: path/to/input
    fail-on: high

SARIF 2.1.0 can be uploaded to GitHub code scanning. The composite action writes per-tool reports under agentsec-sarif/ by default.

OWASP mapping

Heuristic mapping of what this tool helps a reviewer look for. Not an official OWASP endorsement, and not complete coverage of any item. Sources: OWASP Top 10 for LLM Applications 2025 and OWASP Top 10 for Agentic Applications 2026.

Known limits

than *n* words are not detected. Lower -n for stricter checks at the cost of false positives from generic phrases ("if you are unsure, ...").

full-width forms, base64/base64url/hex. Not handled: ROT13, reversed text, letter spacing like "y o u a r e", leetspeak, other encodings.

PL03; tune --fail-on or keep public text out of the prompt you pass with -p.

as sensitive as the prompt itself. --protect values are masked.

Full source, tests, and fixtures: tools/promptleak/ in the repository. Install the kit with pip install git+https://github.com/dunkleschitz/agentsec.git.