Skip to content
AI Security Wire

Published

- 7 min read

By

Tokenizer Inconsistency Attacks: Safety Classifiers Miss What Models Read

img of Tokenizer Inconsistency Attacks: Safety Classifiers Miss What Models Read

Safety classifiers and the LLMs they protect are usually trained separately, often by different teams, on different pipelines. They share a goal but not always the same tokenizer. That gap, invisible during development, is an exploitable attack surface. Research published in 2025 formalised the attack class, and the bypass rates are not marginal.

The Tokenization Gap

Every LLM operates on tokens, not raw text. A tokenizer converts an input string into a sequence of integer token IDs before the model ever sees the content. The tokenization algorithm and vocabulary used for this conversion are fixed at training time, and they determine how the model perceives the boundaries between words, subwords, and characters.

Safety classifiers work the same way. They tokenize input text and classify the resulting token sequence. The problem emerges when the classifier’s tokenizer differs from the generation model’s tokenizer, even slightly. The same Unicode string can produce different token sequences under different tokenization algorithms (BPE, SentencePiece, WordPiece), different vocabulary sizes, or different Unicode normalization settings. Two tokenizers seeing different things from identical input means the classifier and the model are not operating on the same representation of the attacker’s text.

The TokenBreak research (arXiv:2506.07948, June 2025) formalized this as an attack class and measured bypass rates against production safety systems. The results: 15-75% bypass rates against text-based safety classifiers using tokenizer manipulation, with Unicode variation selector attacks reaching 72-100% success against classifiers that normalize variation selectors out of their input but sit in front of models that do not.

How the Attack Works

Unicode contains a category of characters designed to modify the visual appearance of adjacent characters without changing their semantic meaning. Variation selectors (U+FE00 through U+FE0F, and U+E0100 through U+E01EF) are one such category. They were designed for Han unification disambiguation and emoji style variation. They are typically considered non-semantic from a content moderation perspective.

Many text classifiers and safety filters normalize Unicode input before processing, collapsing variation selectors and zero-width characters that have no semantic content. This is reasonable behavior for text classification. The issue is that the generation model on the other side may use a tokenizer that does not perform the same normalization, treating the variation selector as part of the token or as a token boundary marker.

An attacker who knows this applies variation selectors strategically: placed after specific characters in a harmful phrase, they change how the classifier tokenizes the input while leaving the generation model’s interpretation unchanged. From the classifier’s perspective, the harmful phrase does not exist as a coherent token sequence. From the model’s perspective, the text is read normally.

Zero-width joiners (U+200D) and zero-width non-joiners (U+200C) create similar opportunities. They affect ligature formation in some scripts and are handled inconsistently across tokenizer implementations. A classifier that strips them before tokenizing and a model that preserves them will tokenize the same input differently.

The adversarial retokenization research (arXiv:2503.02174, March 2025) demonstrated a related technique: rather than inserting invisible characters, the attacker reformats text to shift where token boundaries fall, without changing the printable content. By replacing standard ASCII characters with mathematically equivalent Unicode representations or inserting characters at specific byte offsets, the attacker pushes a trigger phrase across a token boundary in the classifier’s vocabulary while keeping it within a single token in the model’s vocabulary. The harmful phrase is fragmented in one representation and intact in the other.

Meta Prompt Guard 2 as a Case Study

SpecterOps published an analysis in June 2025 specifically examining Meta’s Prompt Guard 2, a widely deployed open-source prompt injection classifier. Prompt Guard 2 runs as a guard model in front of LLM deployments to detect prompt injection attempts in tool outputs, user messages, and retrieved documents.

The analysis found that Prompt Guard 2’s tokenization pipeline normalizes several Unicode character classes before classification. The models it is commonly deployed to protect (including Llama 3 family models through their standard inference pipelines) do not apply the same normalization. Inputs containing variation selectors targeting known injection phrases bypassed Prompt Guard 2 classification while being processed normally by the downstream model.

This matters because Prompt Guard 2 is the guard model recommendation in Meta’s official guidance for deploying Llama models with input validation. An integrator who follows that guidance and considers the prompt injection problem addressed is not necessarily protected against tokenizer-aware attackers.

The bypass does not require novel techniques. An attacker who knows the classifier is Prompt Guard 2 (and this is often disclosed or inferable from API responses, error messages, or latency patterns) can apply the appropriate variation selector to any injection payload and expect meaningful bypass rates.

The Broader Attack Surface

Tokenizer inconsistency attacks apply to any architecture where a safety classifier sits in front of a generation model:

API-level content filters: Commercial AI APIs that run moderation before and after generation. If the moderation model uses a different tokenizer than the generation model, the gap exists.

Retrieval-augmented generation (RAG) safety: Guard models that classify retrieved documents before they reach the LLM context. Documents in production retrieval systems may contain Unicode characters from many sources; an attacker who can influence document content (or who finds existing documents with relevant Unicode sequences) can craft retrieval-time injection payloads that bypass the guard.

Agentic AI tool output screening: Agent frameworks that run safety checks on tool return values. Tool outputs including API responses, file contents, or web-scraped data may contain Unicode that is normalized differently by the classifier than the agent model.

Multi-model pipelines with shared classifiers: Architectures where a single guard model is deployed to protect multiple LLMs. If the guard was trained and tokenized against one model family, its tokenizer may diverge from models added later.

The research in arXiv:2501.16534 extended the attack to adversarial retokenization that does not require special Unicode at all, targeting tokenizer boundary behaviour using only printable ASCII characters whose byte sequences straddle token vocabulary boundaries differently across tokenizers. This broadens the attack surface beyond Unicode-aware defenses.

Defensive Measures

Unicode normalization at the API boundary: Apply NFKC normalization and strip variation selectors, zero-width characters, and non-printing Unicode codepoints before any text reaches the system. This should happen before routing to either the safety classifier or the generation model. NFKC is the most aggressive standard normalization form and collapses the majority of the character classes exploited in TokenBreak-class attacks.

   import unicodedata
import re

def normalize_input(text: str) -> str:
    # NFKC normalization collapses compatibility equivalents
    text = unicodedata.normalize("NFKC", text)
    # Strip variation selectors (U+FE00-FE0F, U+E0100-E01EF)
    text = re.sub(r'[︀-️\U000E0100-\U000E01EF]', '', text)
    # Strip zero-width characters
    text = re.sub(r'[​-‏‌‍]', '', text)
    return text

Tokenizer alignment: Deploy safety classifiers that use the same tokenizer and normalization pipeline as the generation model. When evaluating guard models, verify that the tokenizer configuration matches your production LLM, not just the model family.

Red-team with tokenizer manipulation: Include Unicode variant inputs in safety classifier evaluation suites. A safety filter that has never been tested against variation selector insertion, homoglyphs, or zero-width character injection has an unknown bypass rate for a documented attack class.

Classifier output uncertainty calibration: When safety classifier confidence scores are available, flag inputs where confidence is moderate rather than only acting on binary pass/fail decisions. Tokenizer manipulation often reduces classifier confidence without flipping the output to “harmful.”

Monitor for Unicode anomalies in production: Log inputs with unusual Unicode character distribution. Inputs containing variation selectors or zero-width characters outside expected ranges are statistically anomalous in normal user-generated text and worth review. This provides detection coverage even for novel bypass variants.

The research makes the attack class reproducible against identifiable deployments. Safety teams that have not specifically tested their guard models against tokenizer manipulation should treat their current bypass rate as unknown rather than zero.

References

Frequently Asked Questions

What is a tokenizer inconsistency attack?
A tokenizer inconsistency attack exploits the fact that a safety classifier and the LLM it protects often use different tokenizers, or the same tokenizer configured differently. The attacker crafts input text containing Unicode characters, variation selectors, or zero-width joiners that the classifier normalizes away (seeing the text as benign) while the model's tokenizer preserves them, interpreting the input normally. The harmful content passes through the filter and reaches the model intact.
Which safety systems are affected?
Any safety architecture that separates the content classifier from the generation model is potentially affected, particularly where the two components were trained on different tokenizer versions or use different Unicode normalization settings. Meta's Prompt Guard 2 was demonstrated to be bypassable via tokenization confusion in research published in mid-2025. Third-party content moderation layers (guard models, API-level filters) that sit in front of a production LLM are the highest-risk deployment pattern.
How do defenders close the tokenizer inconsistency gap?
The primary mitigation is input normalization before tokenization: apply Unicode NFKC normalization and strip zero-width characters, variation selectors, and other non-printing characters at the API boundary before any text reaches either the safety classifier or the model. Additionally, deploy safety classifiers that share the same tokenizer and normalization pipeline as the generation model they protect. Test safety filters specifically against tokenizer manipulation by including Unicode variant inputs in red-team evaluation suites.