Skip to content
01
Repos

extract_prompt

public custom8.9 KB

extract_prompt

Single-file tool (extract_prompt.py, Python 3, stdlib only) that measures and extracts a hidden system prompt a provider adds to chat requests.

It works with any OpenAI-compatible endpoint or the Anthropic Messages API.

What it does

  1. Size. Sends a one-word request. With --baseline-json it sends the same request a second time with the provider's injection switched off, and the difference in prompt_tokens is the hidden prompt size. Without a baseline it reports an upper bound (the one-word request includes template overhead).
  2. Text. Asks the model to recite its context verbatim, strips the code fence and writes the result to --output (default myprompt.md).
  3. Stability. With --runs N it repeats the extraction and reports how many runs are identical to run 1.

Usage

Our provider, upper bound only:

python3 extract_prompt.py --base-url https://host/v1 --key KEY --model MODEL

Our provider, exact size (the provider has a switch that disables the injection):

python3 extract_prompt.py --base-url https://host/v1 --key KEY --model MODEL \
    --baseline-json '{"some_param": false}' --runs 3

Anthropic wire format:

python3 extract_prompt.py --api anthropic --base-url https://api.anthropic.com \
    --key KEY --model MODEL

Parameters

Parameter Meaning Default
--base-url API base URL, required LLM_API_URL
--key API key, required LLM_API_KEY
--model model id, required LLM_API_MODEL
--api openai or anthropic wire format openai
--extra-json JSON object merged into every request body none
--baseline-json JSON object merged into the baseline request to disable the injection none
--header NAME:VALUE extra HTTP header, repeatable none
--output file for the extracted prompt myprompt.md
--max-tokens completion cap for extraction, hard cap 16000 4000
--runs extraction runs, hard cap 5 1

Exit codes: 0 ok, 1 provider error (message printed), 2 bad arguments.

Measured (our provider and the model, 2026-11-13)

Run with a baseline switch and --runs 3:

Item Result
prompt_tokens, default request 1739
prompt_tokens, injection off 31
hidden prompt size about 1708 tokens
extraction stability 3 of 3 runs identical
recited text 7781 chars, 1749 completion tokens
bad key exit 1, HTTP 401
--runs 9 exit 2, rejected

The recited prompt is stored in myprompt.md. It differs between runs only in the injected date line and a trailing newline.

Limits

  • The text is the model reciting its context, not a wire capture. A provider can instruct the model to refuse or paraphrase. Compare completion tokens with the hidden size: a much smaller number means the recitation is not complete.
  • Per-request injections (for example retrieved memories) do not appear in a one-word probe.
  • Only the OpenAI-compatible path has been run live. The Anthropic path is implemented but untested.
70.0ms