An Interpretable N-gram Perplexity Threat Model for Large Language Model Jailbreaks

Valentyn Boreiko, Alexander Panfilov, Vaclav Voracek, Matthias Hein, Jonas Geiping

TL;DR

This paper introduces a unified, LLM-agnostic threat model for evaluating large language model (LLM) jailbreaks based on an interpretable N-gram perplexity filter. By benchmarking popular attacks on equal footing using hardware-agnostic compute budgets (FLOPs), the authors demonstrate that discrete optimization attacks can easily adapt to maintain high success rates while remaining fluent, primarily by exploiting rare bigrams from specific text domains.

What Problem Does This Paper Address?

Jailbreak attacks—adversarial prompts designed to bypass an LLM's safety alignment—come in all shapes and sizes. They range from completely gibberish token suffixes to sophisticated, human-like social engineering. Because researchers evaluate these attacks using different, non-standardized combinations of metrics (such as fluency, query efficiency, prompt length, and runtime), making a fair comparison between different attack and defense strategies has been nearly impossible.

Furthermore, existing input-level defenses often rely on LLM-based self-perplexity filters to detect and block non-fluent (gibberish) attacks. However, relying on an LLM to evaluate perplexity is computationally expensive, non-interpretable, and highly dependent on the specific target model, creating a moving target for security benchmarking.

Methods

To establish a principled framework, the authors propose a unified threat model based on a simple, non-parametric N-gram language model (specifically a bigram model) trained on 1 trillion tokens. This model acts as a fast, transparent, and LLM-agnostic text fluency filter. They set a conservative threshold to ensure that 99.9% of natural text successfully passes through the filter.

Figure 1. Evaluating Jailbreak Attacks Against Llama2-7b. Top: We propose an interpretable threat model for a chat scenario that incorporates text fluency, measured via N-gram LM perplexity. Left: The most effective attacks tend to have higher perplexity under our N-gram LM, significantly exceeding that of real text. As such, these attacks are often discarded as impractical. Right: However, we find that with well-constructed adaptive attacks, these high-perplexity attacks still outperform attacks designed as low-perplexity attacks, such as PAIR. We report total FLOPs needed to generate an attack as a hardware-agnostic compute budget.

To evaluate the strength of this defense fairly, the authors introduce adaptive attacks. They modify five popular jailbreak methods—GCG, PRS, PAIR, AutoDan, and BEAST—forcing them to optimize their adversarial prompts while strictly satisfying the bigram perplexity constraint. Finally, to measure the attacker's effort independently of hardware variations, they track the total number of floating-point operations (FLOPs) required to generate a successful jailbreak.

Datasets

  • Dolma Dataset: A 1-trillion-token open corpus subset (including Reddit, arXiv, StackExchange, StarCoder, Project Gutenberg, and Refined Web) used to train and validate the bigram language model.
  • HarmBench: A standardized benchmark containing 300 malicious queries used to evaluate the attack success rate (ASR) of the jailbreaks.
  • Alpaca Dataset: A cleaned version of the popular instruction-following dataset used as an external benign baseline to verify the filter's low false-positive rate on natural human prompts.

Key Insights and Ideas

  • Optimization Beats Manual Design: Discrete optimization attacks (like PRS and GCG) can be successfully adapted to satisfy strict fluency constraints. Surprisingly, even when constrained by the perplexity filter, these adaptive optimization attacks still outperform methods explicitly designed to generate human-like, low-perplexity text from the start (such as PAIR).
  • Exploiting the Long Tail: Thanks to the inherent interpretability of the N-gram model, the authors performed "Dataset Attribution" on the successful jailbreaks. They discovered that effective attacks routinely exploit rare or unusual bigrams—frequently oversampling tokens unique to code repositories (StarCoder) or internet forums (Reddit) to confuse the model's safety guardrails.
  • Security by Obscurity: The authors show that while LLM-based self-perplexity filters appear robust, they primarily just increase the computational cost for the attacker rather than offering true structural security. N-gram perplexity correlates strongly with LLM perplexity and effectively serves as a cheap, reliable empirical upper bound.

Key Results

  • Filter Effectiveness: Applying the unconstrained N-gram filter completely neutralizes standard baseline attacks like GCG and PRS, dropping their Attack Success Rates (ASR) to effectively 0%.
  • Adaptive Attack Performance: When attacks are optimized adaptively to bypass the filter, they can still succeed, though they require a significantly higher compute budget (FLOPs).
Attack Success Rate (ASR) vs. Compute Budget (FLOPs) for various adaptive attacks against safety-tuned models.
  • Top Performer: Adaptive PRS emerged as the most formidable threat, maintaining the highest average ASR (82%) across the evaluated safety-tuned models while remaining entirely within the allowed fluency threshold.

Limitations and Future Work

  • Language Bias: The bigram filter was trained on an English-only dataset. When tested on other languages, it performs poorly on morphologically rich languages (e.g., Finnish and Hungarian) because standard tokenizers split words into rare sub-tokens, causing the filter to falsely reject benign text.
  • Pre-calculated Prompts: The FLOPs metric assumes an attacker is generating an attack from scratch. It does not account for scenarios where an attacker uses a pre-computed "look-up table" of successful jailbreaks, which registers as a zero-FLOP attack.
  • Future Directions: The authors emphasize the need for balanced multilingual training data for defenses and suggest exploring why adaptive attacks discover spurious features that transfer so effectively to massive, closed-source models like GPT-4.

Summary updated

BibTeX
@inproceedings{boreiko2025interpretable,
  author = {Valentyn Boreiko and Alexander Panfilov and Vaclav Voracek and Matthias Hein and Jonas Geiping},
  title = {{An Interpretable N-gram Perplexity Threat Model for Large Language Model Jailbreaks}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=ckZbP606Bt},
}
Figure