Executive Summary
In-context learning (ICL) allows users to customize Large Language Models (LLMs) by putting private data directly into the prompt, but this exposes the data to prompt-leaking attacks. This paper introduces Differentially Private In-Context Learning (DP-ICL), a framework that protects sensitive prompt data by querying an ensemble of LLMs with disjoint data subsets and aggregating their answers using differential privacy. Crucially, it enables private text classification and open-ended language generation using black-box APIs without requiring any model fine-tuning.
The Threat of Prompt Leaking
Organizations increasingly want to use LLMs with their own proprietary or sensitive data (e.g., healthcare records, financial documents). The easiest way to do this is via In-Context Learning (ICL)—appending relevant private examples to the user's prompt before asking the question. However, malicious users can craft adversarial prompts that trick the LLM into regurgitating the sensitive data hidden in the context.
Historically, the machine learning community has tackled privacy by training or fine-tuning models with Differentially Private Stochastic Gradient Descent (DP-SGD). But DP-SGD is computationally massive, requires access to the model's internal weights (making it useless for black-box APIs like GPT-4 or Claude), and bakes the data into the model, making it incredibly difficult to comply with "right to be forgotten" data deletion requests. The authors tackle the gap of how to achieve mathematical privacy guarantees for inference/prediction using black-box LLMs, particularly for the notoriously difficult task of open-ended text generation.
The DP-ICL Framework
The authors propose a "sample-and-aggregate" paradigm. Instead of putting all private examples into one prompt, the framework processes queries through a secure, multi-phase pipeline.
- Partition the private data into disjoint subsets.
- Prompt the LLM multiple times in parallel, pairing the user's query with a different subset of private data each time.
- Privately Aggregate the ensemble of LLM responses.
The aggregation method depends on the task:
- Text Classification (Private Voting): The system counts the predicted labels from the ensemble, adds Gaussian noise to the vote counts (Report-Noisy-Max), and outputs the winner.
- Language Generation: This is much harder because the output space (all possible sentences) is effectively infinite, meaning a standard voting histogram would be too sparse. The authors propose two novel dimensionality-reduction techniques:
- Embedding Space Aggregation (ESA): Project the ensemble's generated sentences into a semantic embedding space (using OpenAI's embedding models). The system computes a differentially private mean of these embeddings. It then generates a pool of zero-shot candidate answers and returns the one closest to the private mean.
- Keyword Space Aggregation (KSA): Break the ensemble's generated sentences into individual words to create a frequency histogram. The system privately selects the top-$K$ keywords using either the Joint Exponential Mechanism (JEM) or Propose-Test-Release (PTR). Finally, it prompts the LLM to reconstruct a final answer using only those privately extracted keywords.
Datasets and Evaluation
The authors evaluated DP-ICL across three types of tasks:
- Text Classification: SST-2 (sentiment), Amazon (sentiment), AGNews (topic), and TREC (question classification).
- Document Question Answering: PFL-DocVQA (answering questions based on OCR tokens extracted from private documents).
- Dialog Summarization: SAMSum (summarizing chat logs).
Key Insights and Results
- Private Prediction > Private Training: By applying privacy at the inference stage rather than during training, DP-ICL is entirely compatible with black-box APIs. Furthermore, if a user requests their data be deleted, you simply remove it from the prompt database—no model retraining required.
- Beating the Curse of Dimensionality: You cannot easily apply differential privacy token-by-token during autoregressive generation without destroying the text quality. Mapping outputs to a "keyword space" or "embedding space" acts as a low-dimensional bottleneck where privacy noise can be safely injected.
- Keywords beat Embeddings: The KSA method significantly outperformed the ESA method. ESA suffers from information loss during the text-to-embedding projection and relies heavily on the LLM's ability to generate a good zero-shot candidate to match the embedding. Keyword consensus proved to be a much more reliable signal.
- Zero Degradation in Classification: On the SST-2 dataset with a privacy budget of $\epsilon=3$, DP-ICL achieved 95.80% accuracy. This is effectively identical to non-private baselines and actually outperforms previous state-of-the-art models trained with DP-SGD (which hit ~94.6%).
- Strong Generation Performance: For Document QA, using KSA with a strict privacy budget of $\epsilon=1$ resulted in less than a 3% drop in ROUGE-1 scores compared to non-private aggregation.
- Cost-Effective: Because it relies on subsampling, the API costs are highly manageable. Predicting 100 test samples on SST-2 using an ensemble of GPT-3 Babbage calls cost approximately $0.10.
Limitations and Future Work
- Query Limits: Unlike a model trained with DP-SGD (which can answer infinite queries once trained), DP-ICL consumes a portion of the privacy budget with every single query. While the authors show it can handle up to 100,000 queries before performance degrades, it is not suited for infinite-scale deployment without periodically refreshing the private dataset.
- Embedding Reconstruction: The ESA method is currently bottlenecked by the difficulty of mapping a mathematical embedding vector back into fluent text. Future advances in embedding-to-text inversion models could drastically improve this approach.
- Ensemble Optimization: There is an unexplored efficiency-utility trade-off regarding exactly how many disjoint subsets (ensemble size) are optimal for different tasks.
Summary updated