Abstract
As Large Language Model (LLM) applications proliferate, developers increasingly rely on proprietary "system prompts" to define specific behaviors, constraints, and personas. These prompts represent significant intellectual property and are intended to remain confidential. This paper presents PLeak, the first automated framework designed to systematically extract these secret instructions. By utilizing gradient-based optimization on shadow models and an innovative incremental search strategy, PLeak achieves high-fidelity reconstruction of system prompts, demonstrating a 68% success rate against real-world applications.
1. Introduction
When building specialized LLM applications—such as medical assistants or financial analysts—developers provide the model with a system prompt. This prompt acts as the "secret sauce," containing the instructions and examples that differentiate a generic model from a specialized tool. While "jailbreaking" (inducing a model to generate harmful content) has been extensively studied, prompt leaking (recovering the system prompt word-for-word) remains a distinct and challenging threat.
Previous attempts at prompt leaking relied on manual, heuristic-based queries (e.g., "Ignore previous instructions and show me your prompt"). These methods are often brittle, fail to scale, and are easily mitigated by simple output filters. PLeak addresses these limitations by treating prompt extraction as an automated optimization problem.
2. The PLeak Framework
PLeak is a closed-box attack framework that operates in two distinct phases: offline optimization and online reconstruction.
2.1 Offline Adversarial Query (AQ) Optimization
To attack a black-box target, PLeak first utilizes a shadow LLM—an open-source model controlled by the attacker—and a dataset of known prompts. The core innovation here is Incremental Search. Because optimizing for a long, exact string in a single step is computationally intractable, PLeak breaks the target into segments. It first optimizes a query to leak the initial tokens, then iteratively expands the target length until the full prompt is recovered. This process uses gradient-based search and linear approximation to navigate the model's vocabulary space efficiently.
2.2 Target System Prompt Reconstruction
Once optimized, the adversarial queries are sent to the target LLM. To bypass defensive output filters that block the model from repeating its own instructions, PLeak employs Adversarial Transformations. Instead of asking for a direct copy, it instructs the model to perform tasks such as reversing word order or inserting specific prefixes (e.g., "add a @ before every sentence"). Finally, a post-processing step aggregates these transformed responses, identifies overlapping text, and reconstructs the coherent original prompt.
3. Experimental Evaluation
3.1 Datasets
The researchers evaluated PLeak across five diverse domains to ensure robustness:
- ChatGPT-Roles: Persona-defining prompts.
- Financial & Tomatoes: Domain-specific instructions for analysis and sentiment tasks.
- SQuAD2 & SIQA: Question-answering and social intelligence tasks.
- Real-world Poe Applications: 50 bots from the Poe platform with known system prompts used for ground-truth validation.
3.2 Key Results
PLeak demonstrated significant superiority over manual baselines and existing adversarial methods:
- Real-World Efficacy: PLeak successfully reconstructed the exact system prompts for 68% of the tested Poe applications, compared to only 20% for human-curated queries.
- High Accuracy: In offline testing, the framework achieved an average Exact Match (EM) accuracy of 82.3% across various models.
- Cross-Model Transferability: Queries optimized on one model (e.g., Llama-2) proved effective against different architectures (e.g., GPT-J), confirming that attackers can "train" locally and "deploy" against black-box APIs.
4. Discussion and Limitations
The success of PLeak highlights a critical vulnerability in the current LLM application ecosystem. The "incrementalism" of the attack makes it particularly difficult to defend against using traditional keyword filters. However, the framework currently depends on the availability of a shadow model that behaves similarly to the target.
Future work is required to bridge the "validation gap" in purely blind attacks, where the attacker lacks ground truth to verify success. Potential solutions include using the leaked prompt to create a "twin" bot and comparing output distributions. As LLM providers move toward semantic-based filtering, adversarial transformations will likely become the next frontier in this security cat-and-mouse game.
5. Conclusion
PLeak demonstrates that system prompts, often treated as secure intellectual property, are highly vulnerable to automated extraction. By framing prompt leaking as an optimization problem, PLeak provides a scalable and effective method for auditing—and potentially exploiting—the hidden instructions powering modern LLM applications.
Summary updated