In-context learning (ICL) has become a dominant paradigm for adapting Large Language Models (LLMs) to new tasks without the need for expensive weight updates or fine-tuning. By providing a few labeled examples—demonstrations—within the prompt, users can guide the model's behavior effectively. However, this convenience introduces significant privacy risks when those demonstrations contain sensitive information, such as medical records, financial data, or private communications.
The Privacy Challenge in In-Context Learning
The primary risk in standard ICL is that the LLM may inadvertently "regurgitate" sensitive data from its prompt in its generated output. Furthermore, LLMs are susceptible to adversarial "jailbreaking" or prompt injection attacks. An attacker can craft queries specifically designed to trick the model into revealing the private demonstrations included in its context window, as illustrated below.
Traditional privacy measures, such as simple de-identification (e.g., removing names), are often insufficient against sophisticated adversaries with access to auxiliary information. To address this, there is a need for formal privacy guarantees, such as Differential Privacy (DP), which ensures that the inclusion of any single individual's data in the training set does not significantly impact the model's output.
Proposed Method: DP Few-Shot Generation
This paper introduces a novel framework that provides formal DP guarantees for ICL by decoupling the private data from the final prompt. Instead of using raw sensitive records as demonstrations, the authors propose a two-step process to generate synthetic, privacy-preserving few-shot examples.
Step 1: DP Few-Shot Generation
The core of the approach is adapting the Private Aggregation of Teacher Ensembles (PATE) mechanism for text generation. The private dataset is partitioned into $M$ disjoint subsets. For each token to be generated, an ensemble of "teacher" LLMs (each seeing one subset) produces next-token probability distributions. These distributions are then aggregated, and calibrated noise (Gaussian or Exponential) is added to satisfy DP requirements. To maintain generation quality despite the noise, the authors employ a "Reduce Vocab Publicly" (RVP) technique, which restricts the search space to tokens that are likely according to a public model.
Step 2: Synthetic ICL
The resulting synthetic examples are used as the few-shot demonstrations for all subsequent user queries. A key advantage of this approach is the post-processing property of DP: once the synthetic demonstrations are generated under a specific privacy budget ($\epsilon$), they can be reused indefinitely for any number of queries without further privacy loss. This makes the system significantly more efficient than methods requiring noisy aggregation for every single user interaction.
Experimental Evaluation
The researchers evaluated the framework across various text classification and information extraction benchmarks, including AGNews, TREC, and MIT Movies.
- Competitive Performance: The results demonstrate that DP-ICL can achieve performance comparable to non-private baselines. For instance, on the TREC dataset using GPT-3 Babbage, the method achieved 50.7% accuracy at a strict privacy level of $\epsilon=1$, matching the non-private accuracy of 50.6% and significantly outperforming the 35.4% zero-shot baseline.
- Empirical Privacy Strength: Beyond formal guarantees, the authors tested the method against Membership Inference Attacks (MIA). While standard ICL showed high vulnerability (AUC of ~81.8%), the DP-generated prompts reduced attack success to near-random guessing (~50% AUC), confirming the practical effectiveness of the privacy protection.
Conclusion and Future Work
This work provides a robust and efficient path toward private LLM deployment. By generating synthetic demonstrations offline, the system avoids the high latency and privacy budget costs associated with per-query noisy aggregation. While the method shows great promise, future research will focus on improving the coherence of longer synthetic generations and exploring more advanced sampling techniques to further bridge the gap between private and non-private performance.
Summary updated