Better Language Model Inversion by Compactly Representing Next-Token Distributions

Murtaza Nazir, Matthew Finlayson, John Xavier Morris, Xiang Ren, Swabha Swayamdipta

Abstract

Language model inversion is the adversarial task of recovering hidden system prompts from a model's outputs. While previous methods relied on text or high-dimensional logprob vectors, they often faced computational bottlenecks that limited them to single-token analysis. We introduce PILS (Prompt Inversion from Logprob Sequences), a method that exploits the low-dimensional subspace of next-token distributions to perform lossless compression. By utilizing sequences of these compressed vectors, PILS achieves a 2–3.5x improvement in prompt recovery over existing state-of-the-art methods, highlighting a significant security vulnerability in models that expose logprobs.

The Information Bottleneck in Prompt Inversion

In "API-protected" language models, developers frequently embed sensitive instructions or private data within a "system prompt." Inversion methods attempt to reconstruct this hidden string. Traditional logprob-based methods, such as Logit2Text (L2T), were typically restricted to the first generated token because logprob vectors are massive (often exceeding 100,000 dimensions). Processing a long sequence of such vectors is computationally prohibitive. PILS addresses this "information bottleneck" to make multi-step inversion both practical and highly effective.

PILS: Prompt Inversion from Logprob Sequences

The core innovation of PILS is a two-step process that transforms high-dimensional outputs into a compact, manageable format without losing critical information.

The PILS architecture and compression mechanism. The method compresses V-dimensional logprobs into a D-dimensional subspace corresponding to the model's internal hidden state.
  1. Lossless Compression: The authors demonstrate that next-token probabilities are linear projections of a model’s internal $D$-dimensional hidden state. Consequently, the $V$-dimensional probability distribution actually resides in a much smaller $D$-dimensional subspace. Using the additive log ratio (alr) transform, PILS compresses the full distribution into a compact vector of size $D$ (the model's embedding dimension).
  2. Sequence-to-Sequence Inversion: Rather than analyzing a single token, PILS processes a sequence of these compressed vectors (e.g., 16 or 32 steps). These sequences are fed into a T5-base encoder-decoder model that "translates" the probability clues back into the original hidden prompt.

Experimental Setup

The researchers evaluated PILS across several models, including Llama 2, Llama 3.1, and Mistral. The evaluation utilized several datasets:

  • 2M Instructions: Primary training and in-distribution evaluation.
  • Alpaca Code & Anthropic HH: Out-of-distribution (OOD) generalization tests.
  • Awesome GPT Prompts & GPT Store: Real-world system message recovery.

Key Results and Insights

PILS demonstrates that information about a prompt "leaks" out over time, rather than being concentrated solely in the first token. This "temporal leakage" allows the inverter to reconstruct prompts more accurately as more tokens are generated.

Performance of PILS across different datasets and generation steps. Increasing the number of steps significantly improves BLEU scores for prompt recovery.
  • Performance Gains: On Llama 2 Chat, PILS increased the exact recovery rate from 17% (previous SOTA) to 51%.
  • OOD Generalization: On the Alpaca Code set, PILS achieved a 60.5% exact match rate, vastly outperforming the 2.5% achieved by previous logprob-based methods.
  • Sequence Length Scaling: Inverters trained on 16 steps often perform even better when provided with 32 steps at test time, suggesting the model learns a robust relationship between output probabilities and the underlying prompt.

Discussion and Limitations

The effectiveness of PILS reveals that "logprobs" are a significantly larger security vulnerability than previously realized. However, the attack's success depends on API access to logprobs and logit bias parameters. If providers restrict these features, the PILS attack becomes significantly harder.

Future work is needed to explore how these inversion dynamics scale to "frontier" models with larger embedding dimensions and to develop higher-quality datasets of real-world system prompts. Interestingly, newer models like Llama 3 Instruct show higher resistance to inversion, suggesting that modern post-training for instruction-following may provide incidental protection against prompt leakage.

Summary updated

BibTeX
@inproceedings{nazir2025better,
  author = {Murtaza Nazir and Matthew Finlayson and John Xavier Morris and Xiang Ren and Swabha Swayamdipta},
  title = {{Better Language Model Inversion by Compactly Representing Next-Token Distributions}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=FZp6cheXt2},
}
Figure