Abstract
Large Language Models (LLMs) are typically trained and served using a single "canonical" tokenization for any given string. This research reveals that LLMs retain semantic understanding across exponentially many alternative (non-canonical) tokenizations. This "alignment gap" can be exploited to bypass safety filters and jailbreak models without changing a single character of the input text, simply by altering how characters are grouped into tokens.
The Alignment Gap in Tokenization
The tokenizer is a fundamental component of the LLM pipeline, mapping raw strings into subword units (tokens) using algorithms like Byte-Pair Encoding (BPE). While a string like "penguin" is usually tokenized as [p, enguin], it could also be represented as [peng, uin].
The authors identify a critical vulnerability: while LLMs are pre-trained on massive datasets where they encounter various ways to split words, their safety alignment (e.g., RLHF) is typically performed only on the "canonical" tokenizations produced by the standard tokenizer. An attacker can "hide" a malicious request from safety filters by choosing a non-standard tokenization that the model still understands but has not been trained to refuse.
Adversarial Tokenization (AdvTok)
The researchers introduce Adversarial Tokenization (AdvTok), a text-invariant attack that changes only the token boundaries of a prompt. The approach uses two main technical components:
- Multi-Rooted Multi-valued Decision Diagram (MRMDD): A specialized data structure used to efficiently represent and sample the exponential space of valid tokenizations within a certain edit distance from the canonical version.
- The AdvTok Algorithm: A greedy local search that iteratively moves to a neighboring tokenization to maximize the probability of the model generating a target "compliant" response (e.g., "Sure, I can help...").
Robust Semantics vs. Brittle Alignment
A key finding is that LLMs are surprisingly robust at understanding "weird" tokenizations. The semantic signal degrades slowly as the tokenization moves away from the canonical version, but safety alignment—the layer responsible for refusing harmful content—drops off much faster.
As shown in the figure above, while accuracy on harder tasks is lower overall, the model's ability to process non-canonical inputs remains significant even as the distance from the canonical tokenization increases. This suggests that pre-training at scale "leaks" semantic understanding across the tokenization space, while smaller-scale safety training fails to cover these variations.
Key Results and Safety Evasion
The AdvTok attack proved highly effective across state-of-the-art models like Llama 3, Gemma 2, and OLMo 2:
- Jailbreaking: On Llama 3 (AdvBench), AdvTok achieved a StrongREJECT score of 0.275, compared to a canonical baseline of 0.023.
- Safety Evasion: Dedicated safety classifiers like LlamaGuard and ShieldGemma are also susceptible, with bypass rates exceeding 80% in some scenarios.
- Prompt Injection: In man-in-the-middle scenarios, AdvTok increased the success rate on Llama 3 from ~6% to ~77%.
Limitations and Future Defenses
Currently, AdvTok is a white-box attack requiring access to model logits. Furthermore, many commercial APIs only accept raw strings, preventing users from specifying token sequences directly. However, the lack of bijectivity in modern tokenizers (like Gemma 2) means that simple re-tokenization is not a complete defense. The authors suggest that robust mitigation requires integrating safety alignment into the pre-training process or training models to be "tokenization-agnostic."
Summary updated