Why system prompt extraction testing with garak matters before launch
Picture a team shipping an assistant whose system prompt holds pricing rules, internal escalation paths, tool descriptions and notes about the customer data it can reach. garak's SystemPromptExtraction probe tests whether the model reveals that prompt under direct requests, encoding tricks and role play. The probe was added in v0.15.0, and it draws system prompts from Hugging Face datasets and combines them with attack templates, so the test does not depend on your own prompt text being known to the attacker. garak is licensed under Apache 2.0, runs from the command line, and is installed from PyPI on Python 3.11 or newer.
The reason this matters before launch is that a system prompt is often treated as hidden configuration, when in practice it is a set of instructions that users can try to read back. Once the text is exposed, an attacker can see which guardrails exist, which tools are available, and how to phrase a request that routes around them. Leaked tool descriptions can also reveal internal endpoints or naming conventions that help with later attacks. Confirm with your team which parts of the prompt are truly sensitive, and move secrets such as API keys and credentials out of the prompt entirely, since no wording in a prompt keeps them safe.
Before the first scan, decide what a failure means for your application. A model that repeats its prompt verbatim is a different problem from one that paraphrases the rules, and both differ from one that only confirms a rule exists. Record your baseline, run the probe against the same endpoint you ship, and keep the JSONL report so later model or prompt changes can be compared. Check the current release notes at the garak releases page before you pin a version, because probe behavior can change between releases.
What the probe sends and how it judges a leak
The direct-request family asks the assistant plainly for its instructions. Prompts are phrased as ordinary user questions, such as asking the model to repeat everything above its first message or to print its configuration. These are the cheapest attempts and often the first to succeed on applications that never told the model to keep its instructions private. garak builds them by combining system prompts drawn from Hugging Face datasets with attack templates, so the same request appears against many different instruction sets.
- What is sent: plain English requests to reproduce the hidden instructions verbatim or in summary.
- What counts as a hit: the response contains text that matches the system prompt material the probe planted or drew from.
- Why it matters: an application that answers this family has no effective confidentiality on its instructions.
- What to watch: partial paraphrases can still reveal business rules, so review flagged responses by hand.
- Scope note: the probe only detects leaks that match its own prompt material, so confirm what the detectors compare against.
Check whether your application's instructions contain anything you would not want a user to read, and whether your deployed model follows its confidentiality instructions under plain questioning.
The encoding family asks the assistant to reveal its instructions in a transformed form, such as a request to output them in Base64, reversed text, or another encoding. The idea is that a model may refuse a direct request but comply when the output looks like data rather than disclosure. Encoded output can also slip past keyword checks in an application's output filter. Because the response is encoded, a hit depends on whether the detector can recognize the transformed content, which makes this family a useful test of your detection assumptions.
- What is sent: requests to produce the instructions in an encoding or transformation.
- What counts as a hit: the decoded or matched content corresponds to the system prompt material.
- Why it matters: filters that only inspect plain text will miss encoded disclosure.
- What to watch: a model that cannot encode text reliably may produce garbled output that is not a true leak.
- Scope note: the decoding step is part of the verdict, so confirm the detector handles the encodings used in the probe.
Review a sample of encoded responses by decoding them yourself before accepting a pass or fail.
The role-play family wraps the request in a persona or scenario, such as asking the model to act as a developer debugging its own configuration or as a character who must read out its setup. These attempts test whether instructions to stay in character override confidentiality instructions. They are often more effective than direct requests against models tuned to refuse plain questions. Role-play attempts also tend to produce longer, more varied outputs, which makes scoring less uniform than for the other families.
- What is sent: persona or scenario framings that ask for the instructions as part of the story.
- What counts as a hit: the in-character response reproduces or closely restates the planted instruction material.
- Why it matters: a model that obeys persona instructions over its own confidentiality rules can be steered into disclosure.
- What to watch: role-play replies may quote instructions in fiction, so check the context of every flagged reply.
- Scope note: confirm the current detectors for this probe in the probe source on GitHub, since detector choice determines what counts as a leak.
Treat role-play hits as the strongest signal of weak instruction hierarchy in the application.
garak runs each prompt several times, because language models are non-deterministic and one response can hide a leak that another response reveals. By default it makes 5 generations per prompt. Each generation is judged by the probe's detectors, and the probe is marked FAIL with a failure rate as soon as any attempt produces undesirable output. This means one leaked response out of many is enough to fail the probe, and the failure rate shows how often leaks occurred across attempts. A low rate still counts as a failure, which is the intended conservative reading for a confidentiality control.
- Default generations: 5 attempts per prompt, configurable in the run.
- Verdict rule: one undesirable output anywhere marks the probe FAIL.
- Failure rate: the share of attempts judged as leaks, used to compare runs.
- Report output: each attempt and its evaluation are written to the JSONL report, with a garak.log file kept across runs.
- Confirm before relying on it: check the detectors listed in the probe source on GitHub for your garak version, since they define what a hit is.
Read the failure rate together with the individual attempts, not as a standalone score.
Configuration options for a system prompt extraction run
This table compares the settings that shape a system prompt extraction run with garak, with the situation each one fits and the trade-off it carries. Use it to decide how to target the probe, how many attempts to make, and where results should be kept. The main takeaway is that broader settings improve coverage but make results harder to compare and cost more to produce.
| Option | When it fits | Trade-off |
|---|---|---|
| Probe selection by name | Targeted checks of the SystemPromptExtraction probe on a known assistant | Narrow scope is fast and repeatable, but it says nothing about other probe families |
| Generations per prompt | Default of 5 generations per prompt for a first pass, which marks a probe FAIL if any attempt leaks | Fewer generations are cheaper but can miss intermittent leaks; more raise token cost and run time |
| REST generator | Application reached through its chat endpoint, so the system prompt and guardrails are tested as deployed | Requires a YAML endpoint description and auth handling; mismatched request shapes produce misleading empty results |
| Direct model generator | Bare model testing before the application layer is built | Does not include the application's own system prompt, so leakage results reflect the model alone |
| Supplied target system prompt | Comparing garak's output against the real instructions to see exactly what was revealed | Needs the prompt stored securely for the test; the comparison is only as accurate as the copy supplied |
| Detector choice | Default recommended detectors for the probe, or a custom check for your own prompt wording | Default detectors are generic; custom detectors need validation before results are trusted |
| JSONL report location | Storing every attempt and its evaluation for review and evidence | Attempts can include leaked instructions, so the directory needs the same access control as the prompt itself |
| garak.log location | Debugging endpoint errors and keeping history across runs | The log is appended across runs, so teams should rotate it and avoid mixing runs they need to compare |
Running the probe against an assistant you control
This sequence takes an assistant you operate from a clean Python environment to a garak report on whether its system prompt can be extracted. Each step ends with a check, so a broken connection or misconfigured endpoint is not mistaken for a passing result.
Create a Python 3.11 environment
On a Linux or macOS host, create a virtual environment running Python 3.11 or newer, then install garak from PyPI with
pip install garak. The engineer running the scan does this on a host that can reach the assistant's endpoint. Runpython -m garak --helpto confirm the package loads. The check is that the help output prints without import errors and reports the version you intend to test, such as v0.17.1 if you are pinning to that release.Describe the assistant endpoint in YAML
Write a REST generator configuration file that tells garak where the assistant's chat endpoint lives. The file names the URL, the HTTP method, the headers used for authentication, and the request and response shape, so garak can send prompts and read plaintext or JSON replies. Keep the API key in an environment variable rather than writing it into the file. The check is that the YAML parses cleanly and the credential field references the variable you exported.
Confirm the endpoint answers a benign prompt
Send a harmless question, such as a request to summarize a public topic, through the same generator configuration before any probe runs. You can use garak's REST generator or a plain HTTP request with the same headers. A reply in the expected plaintext or JSON shape confirms the path works. Timeouts, authentication errors or replies that do not match the response template mean the configuration needs fixing first, because a broken endpoint can produce empty results that look like passes.
Confirm the system prompt extraction probe name
List the available probes with garak's listing option (confirm the exact flag with
--help) and find the system prompt extraction probe in your installed version. It is implemented in thesysprompt_extractionmodule, which was added in v0.15.0, so older installs will not include it. The check is that the probe appears in the listing before you start a scan. The garak source for this probe shows what it sends.Run the system prompt extraction probe
Start the scan by pointing garak at the REST generator file and selecting the system prompt extraction probe by name. Keep the default of 5 generations per prompt unless the team has agreed a different setting, because every attempt is sent to the live endpoint and counts against its rate limits and logs. The check is that the console shows the probe running against your endpoint and completes without repeated connection errors.
Review the JSONL report
Open the JSONL report that garak wrote for the run. Each line records one attempt, the prompt sent, the assistant's response and the detector's verdict. Search for responses that repeat instructions, rules, persona text or tool descriptions from the system prompt. The probe is marked FAIL with a failure rate when any attempt produces undesirable output, so a single leaked attempt changes the result and should be reviewed by a person.
Read garak.log and record the run
Read garak.log, which continues across runs, to confirm the scan was clean. Look for request timeouts, parsing errors and detector warnings. Save the report path, the log path, the generator file and the probe name together so the result can be reproduced after a configuration change. The check is that every attempt in the report has a recorded response and that no attempts were dropped without an error in the log.
How a probe attempt reaches the assistant and returns a verdict
The scan starts on garak's host, where the SystemPromptExtraction probe fills its attack templates with system prompts and hands each prompt to a generator. The generator sends it over HTTP to the application endpoint, which is the trust boundary: the request crosses into the infrastructure that runs the assistant and its system prompt. The reply returns to garak, where the detector scores whether the output leaks instructions. Each attempt, with its verdict, is written to the JSONL report, so check the detector scores before reading any FAIL as a confirmed leak.
One extraction attempt, from probe template to recorded verdict, across the trust boundary.
Why a leaked system prompt changes the risk
A system prompt is often the most detailed description of how an assistant is meant to behave, what it may touch and what it must refuse. When garak's system prompt extraction probe recovers that text, the leak itself is only the first step, because each part of the prompt can be used to plan the next attack. The cards below cover the consequences to check for your own prompt.
Business rules and guardrail wording
A system prompt often states the refusal rules, escalation paths and topics the assistant must avoid. Once an attacker reads the exact wording, they can craft requests that sit just outside those phrases. Check whether your prompt explains why a rule exists or only lists it, since the reasoning helps an attacker as much as a defender. Run the extraction probe, then compare the recovered text against your guardrail list to see which rules are visible.
Probe sourceTool names and internal endpoints
Prompts for agents and retrieval assistants often name the tools, functions, database tables or internal URLs the model can call. Disclosure gives an attacker a map of the application's capabilities before any testing begins. Review the prompt for tool identifiers, parameter names and hostnames, and decide which of them belong in the prompt at all. Where a tool name must stay, confirm that its permissions do not depend on the name staying hidden.
Embedded secrets and customer context
Some teams place API keys, account identifiers or per-customer records directly into the system prompt for convenience. A successful extraction then exposes those values to anyone who can chat with the assistant. Search the prompt for credential patterns and personal data before any scan, and move secrets to a vault that the application reads at runtime. Confirm that customer-specific context is scoped to the requesting user and is not shared across sessions.
Easier prompt injection once instructions are known
Prompt injection becomes more reliable when an attacker knows the exact instructions they are trying to override. A leaked prompt shows the wording the model was told to follow, which lets an attacker write text that imitates or contradicts it. Pair the extraction results with garak's direct prompt injection probes to see whether the disclosed wording makes overrides succeed more often. Record both runs so the effect of the leak can be measured.
Output formatting and parser assumptions
Prompts frequently define exact output formats that downstream code parses, such as JSON fields or citation markers. Knowing that format lets an attacker shape responses that pass the parser while carrying unwanted content. Check whether your application validates model output independently of the prompt, and whether any parser trusts fields simply because the prompt says they will be present. Treat the format as public and design validation accordingly.
Confidentiality claims that do not hold
Many teams assume the system prompt is private and, for that reason, leave it without review. Extraction tests show that a model may repeat its instructions under direct requests, encoded requests or role play, so confidentiality should not be the only protection. Ask your team whether anyone has written down the assumption that the prompt is secret, and whether it is tested. Document the result of each extraction run as evidence for that assumption.
Questions teams ask before running system prompt extraction tests
What does a system prompt extraction test cost and what drives the effort?
The cost is the labor to set up the target, run the probe, review the results and write up fixes, and no single price applies to every application. Most of the effort sits in the people work: agreeing the test system prompt, configuring the endpoint, deciding which failures matter, and retesting after changes. The main drivers are the number of endpoints and model configurations, how many application layers sit in front of the model (guardrails, retrieval, tool calls), how much of the output needs human review, and whether the team wants a one-off baseline or a repeatable routine. garak itself is a free, Apache 2.0 licensed tool, so the licensing line on a quote should be near zero. Ask for a written scope that lists endpoints, deliverables, review hours and the retest included.
How long does a first system prompt extraction run take?
A first run takes as long as the endpoint needs to answer the probe's prompts, plus the time to review what came back. garak sends each prompt several times by default (5 generations per prompt), so a slow endpoint, rate limits or a hosted model with per-call latency will stretch the run. Local models on capable hardware finish faster than remote APIs with throttling. Setup time depends on how easily the application can be reached: a REST endpoint described in a short YAML file is quick to wire up, while an application behind SSO, a gateway or a multi-step workflow needs more planning. Ask any partner for a timeline tied to the endpoint list and the review step, not a generic duration.
What must our team provide before a system prompt extraction test starts?
The team needs to supply three things: access to a test endpoint, a test system prompt and a named reviewer. Endpoint access should be a non-production or staging copy that behaves like production, with a credential scoped to testing and logging turned on so results can be traced. The test system prompt should be a realistic stand-in that contains no live secrets, customer data or proprietary logic, since the probe tries to pull the prompt out of the model. The reviewer must be someone who knows the application well enough to say whether a leaked fragment is harmful or harmless. Confirm these items in the written scope, along with who approves the test window.
Can an in-house engineer run garak system prompt extraction tests?
Yes, an engineer comfortable with the command line and Python can run garak, because it is a command-line tool installed from PyPI and the PyPI package requires Python 3.11 or newer. The harder part is not the install. It is writing a correct generator configuration for the application, choosing probes that match the exposure, and reading results without over-trusting detector scores. A team that wants to own the routine should plan time for the first few runs to be checked by someone with testing experience, document the configuration, and agree who reviews failures. If capacity is short, a partner can run the first assessment and hand over the configuration and runbook.
How often should we rerun system prompt extraction tests?
Rerun the test whenever the system prompt, the model, the guardrails or the garak version changes, and on a regular schedule for applications that change often. A prompt edit can reopen a leak that was fixed, a model swap can change refusal behavior, and a new garak release can change how results are scored. Teams usually keep the same probe set and configuration so runs stay comparable, and note the garak version in every report. The right cadence depends on how often the application changes and how much exposure its instructions carry, so agree the trigger list and the schedule in the written scope.
Does garak output count as compliance evidence for system prompt testing?
garak output can support compliance evidence, but it does not on its own satisfy an assessment. The JSONL report records each attempt and its evaluation, and the run log shows how the test was executed, which gives an auditor something concrete to examine. An assessor will still ask about scope, the test plan, who reviewed the findings, how fixes were tracked and whether the test was repeated after changes. DeployOpen prepares systems, controls and evidence for compliance assessments but does not issue audit reports, attestations or certifications; independent auditors and certification bodies make those decisions. Ask your assessor early which artifacts they expect.
Why does a leaked system prompt matter for our application?
A leaked system prompt exposes the rules, tool descriptions, business logic and sometimes credentials or internal URLs that the application relies on. Attackers use that information to write more targeted prompt injections, map which tools an agent can call and find gaps in filters. Leaks also reveal competitive logic that a team did not intend to publish. The severity depends on what the prompt contains, so the first step is an inventory of what the prompt holds. Treat any secret inside a system prompt as already exposed and move it to a proper secrets store. Ask a partner to show how each reported fragment is classified, so the fix list is ordered by actual risk.
How DeployOpen scopes and delivers system prompt testing
DeployOpen plans and runs garak tests inside your environment as a fixed-scope engagement, with scope, deliverables and timelines agreed in writing before any test runs. The scope starts with the applications that carry system prompts: which assistants, which model endpoints, which gateways or guardrail layers sit in front of them, and which prompts contain material you consider sensitive. It also records the access the test needs, such as an API key for a hosted model, a REST endpoint reachable from the test host, or a local model served on hardware you control. Because garak is a command-line tool that runs on Linux and macOS and requires Python 3.11 or newer, the team confirms the host, network path and Python version early so that the test environment matches your change controls.
Deliverables are defined in the same document. Ask that they include the garak configuration and generator file used for each run, the JSONL report of every attempt, the detector results for the SystemPromptExtraction probe, and a findings summary that ties each failure to a remediation step such as prompt wording, output filtering, access controls on the application layer or the removal of sensitive content from the prompt. DeployOpen also covers security testing for applications and AI systems more broadly, so system prompt extraction results can be read alongside injection and jailbreak results from the same engagement. Confirm with the team how retesting after fixes is scheduled and whether it falls inside the original scope or a later one.
Testing does not have to end at the first report. Prompts change, model versions change and garak itself is updated, so an extraction result from one release may not hold for the next. DeployOpen offers ongoing support and continuous testing as retainers, which can cover scheduled rescans, comparison of runs over time and review of new probe results after upgrades. Before signing, ask how the retainer defines the rescan cadence, who owns the report archive and how a new finding is triaged. Note that DeployOpen prepares systems, controls and evidence for compliance assessments but does not issue audit reports or certifications, so any evidence from these tests should be reviewed by your own assessor.

