Differentially Private In-context Learning via Sampling Few-shot Mixed with Zero-shot Outputs

James Flemings, Haosheng Gan, Hongyi Li, Meisam Razaviyayn, Murali AnnavaramarXiv 2025

Abstract

In-context learning (ICL) has shown promising improvement in downstream task adaptation of LLMs by augmenting prompts with relevant input-output examples (demonstrations). However, the ICL demonstrations can contain privacy-sensitive information, which can be leaked and/or regurgitated by the LLM output. Differential Privacy (DP), a widely adopted privacy safeguard, has emerged to mitigate this privacy leakage, with recent work demonstrating strong privacy-utility tradeoffs in classification tasks for ICL. However, generation tasks for ICL are challenging due to the high-dimensional output space of open-ended generation. To this end, we propose $\texttt{dps-mozo}$, Differentially Private Sampling by Mixing One-shot with Zero-shot Outputs, a decoding framework that generates DP text by sampling from the product of multiple one-shot outputs mixed with a zero-shot output. This mixing effectively reduces the amount of information that can be leaked by each demonstration. By utilizing the inherent randomness in sampling from the mixed distributions, we can achieve DP without adding noise, thereby improving the privacy-utility tradeoff. Our experimental evaluations show $\texttt{dps-mozo}$ can achieve a strong privacy guarantee, $\epsilon=2$, with minimal utility degradation compared to non-private few-shot learning, $\textbf{0.3}$% ROUGE-L F1 score decrease on the SAMSum dataset with Gemma 2 2B.

Introduction

In-context learning (ICL) allows Large Language Models (LLMs) to adapt to new tasks by including a few demonstrations in the prompt. While effective, this practice poses significant privacy risks if the demonstrations contain sensitive data, such as medical records or private communications. The model may inadvertently leak or regurgitate this information in its generated outputs.

Overview of the LLM provider-client interaction involving private data.

Differential Privacy (DP) offers a mathematical framework to prevent such leaks. However, applying DP to open-ended text generation is notoriously difficult. Existing methods often focus on simple classification tasks or require immense computational resources. Traditional DP also typically injects noise into the model's logic, which can severely degrade the coherence and quality of the generated text.

Methodology: The DPS-MOZO Framework

We introduce DPS-MOZO (Differentially Private Sampling by Mixing One-shot with Zero-shot Outputs), a framework designed to provide robust privacy without the typical "utility tax." Instead of adding external noise, DPS-MOZO leverages the inherent randomness of LLM token sampling.

The DPS-MOZO framework architecture (a) and its deployment modes (b).

Distribution Mixing and Adaptive Bounding

For every token generated, the system calculates two probability distributions: one based on a private example (one-shot) and one based only on the model’s general knowledge (zero-shot). These are mixed using a parameter $\lambda$. The framework solves an optimization problem in real-time to find the largest $\lambda$—representing the maximum influence a private example can have—that still adheres to a strict privacy budget (Renyi Differential Privacy).

Ensemble Decoding and Deployment

The final token is sampled from the product of multiple mixed distributions. DPS-MOZO supports two deployment modes:

  • DPS-MOZO+On: Applies privacy protections during live queries.
  • DPS-MOZO+Off: Generates "private" synthetic examples offline, which can then be used freely in standard ICL without further privacy restrictions.

Evaluation and Results

The framework was evaluated on several generation tasks, including abstractive summarization (SAMSum), data-to-text generation (E2E), and text simplification (WikiLarge).

Key Findings

  • High Utility: On the SAMSum dataset using Gemma 2 2B, DPS-MOZO achieved a strong privacy guarantee ($\epsilon = 2$) with only a 0.3% drop in ROUGE-L score compared to a non-private model.
  • Efficiency: Unlike prior methods requiring ensembles of 100+ prompts, DPS-MOZO works effectively with just 4 shots, making it practical for real-world applications.
  • The "Spike" Phenomenon: Analysis revealed that private examples are most influential at the start of a sentence. As generation progresses, the model relies more on its own previous tokens, allowing the privacy-mixing parameter $\lambda$ to increase naturally over time.
  • Empirical Safety: Membership Inference Attacks showed an adversary's success rate near 50%, indicating that the theoretical privacy guarantees translate to actual protection against data extraction.

Conclusion and Future Work

DPS-MOZO demonstrates that strong privacy and high utility are not mutually exclusive in LLM generation. However, the method currently requires access to the model's logits, which limits its use with "black-box" APIs. Future research will explore techniques like logit bias to extend these privacy benefits to closed-source models. Additionally, the framework assumes that only sampled tokens are released; releasing full probability distributions would compromise the privacy guarantee.

Summary updated

BibTeX
@misc{flemings2025differentially,
  author = {James Flemings and Haosheng Gan and Hongyi Li and Meisam Razaviyayn and Murali Annavaram},
  title = {{Differentially Private In-context Learning via Sampling Few-shot Mixed with Zero-shot Outputs}},
  year = {2025},
  eprint = {2501.19287},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.19287},
}
Figure