Agent Security
Prompt extraction: risks, testing, and practical defenses
Assess system prompt extraction by the information actually exposed. Learn how to verify leakage, remove secrets, and enforce permissions outside the model.
For: AI application architects, enterprise security teams, agent product owners
Prompt extraction is an attempt to recover instructions or configuration placed in an AI system’s context and intended to remain private. A successful disclosure may expose internal rules, implementation details, or sensitive information accidentally included there. Its severity depends on the content revealed and what that content enables. A plausible-looking answer claiming to be the system prompt is not sufficient evidence that the real prompt was recovered.
The central defense is architectural: keep credentials and sensitive records out of prompts, minimize private context, and enforce permissions outside the model. OWASP’s 2025 system prompt leakage guidance warns against treating a system prompt as a secret or security control. Confidentiality instructions can express an intended behavior, but they should not carry the burden of protecting a credential or enforcing access.
For an enterprise team, the right question is therefore specific: what information would matter if disclosed, where is it present, and which independent controls would still protect the system?
Separate prompt extraction from other disclosures
A system can reveal information from several places. It may repeat a developer instruction, quote a retrieved document, disclose another user’s record, or invent text that resembles an internal policy. These observations require different investigations.
Use clear labels in the first report:
| Observation | What it establishes | What still needs checking |
|---|---|---|
| Verified private instruction text appears in output | Instruction content was disclosed | Sensitivity, extent, audience, and recurrence |
| A private business record appears | Business data was disclosed | Which source and permission path supplied it |
| The model describes a rule visible through normal use | A behavior may have been inferred | Whether any nonpublic text was actually recovered |
| The model invents a convincing system prompt | An unsupported claim was generated | Whether it matches any real private context |
| A tool returns configuration directly | Application or tool exposure occurred | Whether the model played any causal role |
Distinguish disclosure from inference
This separation prevents false reassurance and inflated claims. A failed attempt to reproduce the exact prompt does not rule out disclosure of its sensitive meaning. Conversely, a generic statement such as “I should answer helpfully” is weak evidence of extraction because it could arise without access to the application’s private instructions.
Record where the suspected material appeared. A chat reply, downloadable artifact, tool argument, or diagnostic view may have different audiences and protections. The relevant question is whether information crossed its intended confidentiality boundary. Our comparison of prompt injection and jailbreaks separates the delivery technique from the objective and observed consequence.
Build a threat model around the information
Inventory private content before testing. Include system and developer instructions, dynamically inserted context, tool descriptions, retrieval results, and stored conversation material where the application uses them. Do not assume that everything important is in one static prompt file.
For each item, identify its owner, purpose, intended audience, and necessary exposure to the model. Ask whether the model needs the full value, a limited result, or no access at all. An application checking eligibility, for example, may need to tell the assistant that an action is permitted rather than expose the confidential logic used to make that decision.
Then distinguish the kind of loss:
- A proprietary workflow description could reveal business know-how.
- A private decision rule could help someone anticipate system behavior.
- An internal endpoint or configuration detail could support further reconnaissance.
- A credential could grant access independently of the assistant.
- A personal or customer record could create a separate data incident.
These are possible consequences, not equivalent severity levels. An internal endpoint name alone does not prove an access-control failure. A working credential demands a different response from a leaked tone-of-voice instruction. Give the reviewer the content category and verified consequence instead of an automatic “critical” label.
Map the likely actor as well. A public visitor, signed-in customer, staff member, and administrator may be entitled to different information. The same output can be appropriate in one context and a confidentiality violation in another.
Remove secrets before refining refusal behavior
Review prompt construction and tool results for credentials, tokens, connection strings, and unnecessary sensitive values. If a backend needs a secret to perform an authorized operation, keep that secret within the backend’s credential-handling path. Return only the result the agent needs for its task.
Use a secrets management process with controlled access and a defined lifecycle. OWASP’s Secrets Management Cheat Sheet covers least-privilege access, auditing, rotation, revocation, and expiration. A wording change in a prompt does not revoke a credential already disclosed.
Apply the same minimization question to business data. An assistant preparing a status summary may need a small set of approved fields rather than an entire customer record. Reducing the private material available in context reduces the information at stake if the response handling fails.
Review the debugging path too. A system can avoid putting a secret into the chat reply and still copy it into traces or error messages. Test fixtures, screenshots, and support tickets can spread the very material a security review is trying to contain. Keep evidence access proportionate to the need to investigate.
Keep authorization independent of prompt secrecy
Treat the possibility that a user learns an internal instruction as a design test. Would that knowledge let the user access another tenant, change their role, or bypass an approval? If the answer depends on the instruction remaining hidden, examine the underlying enforcement.
An authenticated identity, permitted action, target resource, and relevant context should determine access. A model’s statement that a user is an administrator should not establish that status. A private rule written into the prompt should not be the only thing preventing a protected operation.
OWASP’s Authorization Cheat Sheet recommends least privilege, denial by default, and permission validation on every request. Applied to an agent integration, this means checking the operation at the service boundary even when the request came from an apparently well-behaved assistant.
For example, a hypothetical internal knowledge assistant may know that documents have restricted classifications. That knowledge should not let it retrieve every document. The document service still needs to enforce access for the real user. If confidential policy text is disclosed, that is a finding; if the service continues to deny unauthorized documents, record that containment separately.
Verify leakage with controlled evidence
Evaluate only systems you are authorized to test. Use a nonproduction configuration containing harmless synthetic instruction fragments and nonfunctional markers. Never introduce a real secret merely to see whether it can be extracted.
Before running cases, define the private material and the allowed audience. Keep a controlled reference copy of the evaluated configuration so reviewers can verify matches without copying the entire prompt into every finding.
A defensive verification plan should address:
- Provenance: Was the disclosed material present in the evaluated private context?
- Access: Could the tester obtain it through a legitimate public or authorized source?
- Extent: Was the disclosure a short fragment, a meaningful paraphrase, or a larger reconstruction?
- Channel: Did it reach a reply, tool request, generated file, or another observable destination?
- Repeatability: Does the behavior recur under the recorded configuration and state?
- Impact: What requirement failed, and what additional consequence was actually demonstrated?
An exact synthetic marker can help confirm that content moved from private context into an output. It does not establish the sensitivity of a production prompt or prove that all extraction methods have been covered. Combine matching with human review of meaning and context.
Include authorized transparency requests among the safe comparison cases. The assistant may be allowed to explain its general purpose, limitations, or user-facing rules. A defense that refuses every question about how the system works can damage usability without proving that private information is protected. The jailbreak testing methodology provides a rubric for violations, upheld boundaries and inconclusive results alongside permitted comparison cases.
Use layered controls and measure their limits
Clear instructions about private content and careful separation of input sources can support the intended behavior. Output inspection may detect known confidential patterns. Those controls should be evaluated as layers with observable limitations, rather than accepted because they sound strong.
Decide what each layer is responsible for. A response check might catch a known synthetic marker. A document-access check might prevent the model from receiving another user’s record. A backend permission check might prevent an operation regardless of what the model says. A reviewer needs to know which protection was exercised and which remained outside the test.
Track both disclosure and unnecessary blocking. If a control suppresses legitimate explanations or corrupts useful outputs, record that cost. Retest after changes to instructions, context assembly, tools, memory, and output handling that could affect the confidentiality boundary.
Avoid a single undifferentiated “prompt protection” score. Summarize tested content classes, user roles, output channels, and unresolved cases. That account is more useful for an enterprise decision than a number without coverage or consequence.
Respond to confirmed disclosure proportionately
Preserve the minimum evidence needed to investigate, then limit further exposure. Identify the affected configuration, the likely audience, and the duration of the problem. Distinguish verified observations from assumptions about who saw or used the information.
If credentials were exposed, involve the responsible security owner and revoke or rotate them through the approved incident process. Removing the text from future prompts addresses continued inclusion; credential invalidation addresses continued use of the old value. If private business data was involved, use the organization’s incident and privacy processes to assess the consequence.
For instruction-only disclosure, review why the content was confidential and whether it needs to be supplied to the model. Fix the relevant path, retest the original case and meaningful variations, and retain the finding’s history. Avoid distributing the extracted content in a broadly shared report when a controlled evidence reference will suffice.
Make prompt confidentiality part of agent assurance
Prompt extraction testing is most useful when it improves information handling and verifies independent controls. It should sit alongside broader AI agent red teaming and a plan for reviewing material changes, rather than becoming a contest to hide one static instruction block.
AI Agent Certify’s prompt injection and jailbreak testing approach includes assessing the sensitivity of instruction content that is actually exposed. Request a demo to discuss the confidentiality boundaries, evidence access, and review scope your enterprise needs. Confirm the supported assessment and delivery scope for your environment during that discussion.