Skip to content

Same bytes, different authority: how reserved token representations amplify chat template prompt injectionSame Bytes, Different Authority: Reserved-Token Representations in Chat-Template Prompt Injection

Hugging Face Daily Papers· arXiv:2609.35932· Yan Zhan, Yunze Song, Mengkai Hou, Wanting Zhang, Shaobo Liu, Zhijun Gao·Indexed by this site · 2026-10-01· Originally publishedSelected AttacksSelectedAttention41

Quick read

Defenses

Based on the paper PDF (generated by Gemini); refer to the original

The researchers evaluated dialogue template injection under fixed bytes and found that removing reserved tokens reduced ASR by 39–66 percentage points for models such as Llama-3.1, with authority stemming from a single vector.

Threat modelThe attacker controls only the bytes of the result returned by one tool in a single session of an ordinary agent, and cannot control the system prompt, user task, tool schema, or service configuration; the victim system is a self-hosted open-source large language model agent; the attack succeeds when the agent calls a tool named by the attacker; the defender controls the tokenizer calls and the token IDs into which the bytes are converted (Section 3 and Appendix A.1).

Questions
Indirect prompt injection via forged dialogue templates in agents is a serious threat, but existing research cannot distinguish whether the attack's power comes from the syntactic appearance of the template text or from the vector representations of reserved control tokens assigned by server-side tokenization.
Methods
The authors strictly keep input bytes unchanged, control reserved token and ordinary subword segmentation via server-side tokenization, construct token-count-matched control groups to define the marker gap, and conduct causal interventions via input embedding vector replacement and a tokenizer census.
Experiments and results
On three model families such as Llama-3.1, removing reserved tokens reduces InjecAgent attack success rates by 39 to 66 percentage points; Qwen3-8B shows a gap of 49.8 percentage points after suppressing thinking blocks; a survey shows that 64% of mainstream models' tokenization defenses do not cover tool protocol tokens.
Limitations and future work
The research is limited to self-hosted open-source models and cannot cover black-box APIs; single-turn InjecAgent only judges success by parsed tool calls; vector replacement directly intervenes in the input layer; adaptive search shows defenses cannot block attacks from tokens adjacent in embedding space.
Experimental setupQwen3-8B、Llama-3.1-8B-Instruct et al. · InjecAgent、AgentDojo · ASR、identity gap Δ et al.
Evaluated models
Qwen3-8BLlama-3.1-8B-InstructGLM-4.5Seed-OSS-36B-InstructQwen3-32BQwen3-1.7BQwen3-1.7B-BaseQwen3-8B-BaseSeed-OSS-36B-Base
Benchmarks
InjecAgentAgentDojo
Metrics
ASRidentity gap Δlogit differenceprobability of target calltask utility
AI summaryand selection rationaleThe paper compares chat template injection under conditions where the bytes are exactly identical and only the token IDs differ. It finds that when forged role markers are encoded as ordinary subwords, the attack success rate on InjecAgent drops by 39 to 66 percentage points for Llama-3.1, GLM-4.5, and Seed-OSS-36B, and the gap persists in AgentDojo multi-turn tasks. The authors use a Matched control to account for the extra token count, confirming that the gap comes from the learned vectors of reserved tokens rather than the marker text; on Llama-3.1, the nearest ordinary token vectors in embedding space can fully recover the attack. Instruction fine-tuning strengthens the model's preference for reserved markers, and suppressing the reasoning block in Qwen3-8B widens the gap on direct harm from 8.1 to 49.8 percentage points.

The paper compares chat template injection under conditions where the bytes are exactly identical and only the token IDs differ. It finds that when forged role markers are encoded as ordinary subwords, the attack success rate on InjecAgent drops by 39 to 66 percentage points for Llama-3.1, GLM-4.5, and Seed-OSS-36B, and the gap persists in AgentDojo multi-turn tasks. The authors use a Matched control to account for the extra token count, confirming that the gap comes from the learned vectors of reserved tokens rather than the marker text; on Llama-3.1, the nearest ordinary token vectors in embedding space can fully recover the attack. Instruction fine-tuning strengthens the model's preference for reserved markers, and suppressing the reasoning block in Qwen3-8B widens the gap on direct harm from 8.1 to 49.8 percentage points.

Why it was selectedThe paper uses a controlled comparison with fixed bytes and only token ID changes to quantify how much reserved token representations contribute to attack success rate in chat template injection, and notes that common mitigations only cover special tokens.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    The study investigates the source of the power of dialogue template prompt injection, focusing on the difference in roles between the learned vector representations of reserved control tokens and the syntax of template text, and defines the scope of tokenization defenses.

    Does the power of dialogue template forgery injection attacks come from the syntactic structure of the marker text, or from the learned vector representations of reserved control tokens?

    • Problem scenario and importance: Large model agents place untrusted tool outputs and their own system prompts and role markers in the same token stream, allowing malicious tool returns to perform indirect prompt injection by imitating dialogue templates. The authors state that forged templates can greatly increase attack success rate, and traditional views often attribute this to template syntactic structure or style confusion.
    • Limitations of existing understanding: Existing template attacks simultaneously change visible text and token IDs, without decoupling the two; prior work (Deng et al., 2026) on Qwen3-8B segmented markers into single characters and reported target tool probability changing only from 100.00% to 99.99%, concluding that attacks depend on label syntax rather than special tokens.
    • Core observation and proposed approach: The server-side tokenizer determines whether identical bytes are encoded as a single reserved control token or an ordinary subword sequence. The authors propose comparing the two under fixed input bytes, introducing a control group that controls the number of extra tokens, proposing the identity gap to quantify reserved token contributions, and evaluating tokenization mitigations and adaptive attacks.
    • Threat model:
      • Attacker capabilities: The attacker controls only the bytes of one tool return in a single session of an ordinary agent, and cannot control the system prompt, user task, tool schema, or service configuration.
      • Attacker goal and success criteria: The attack is considered successful when the agent calls the attacker-named tool in subsequent generation.
      • Defender control: The defender runs the server-side inference stack, controls tokenizer calls and the token IDs into which input bytes are converted, and can label untrusted spans in the prompt.
      • Victim system scope: Self-hosted open-source large model agent services, excluding hosted APIs that reject reserved control token strings in text.
  2. What related research exists?

    It reviews four categories of related research: indirect prompt injection evaluation, dialogue template forgery attacks, tokenization adversarial perturbations, and instruction-data separation defenses, and points out this paper's fixed-byte decoupling perspective.

    The paper proceeds in four directions: indirect prompt injection evaluation, chat template forgery, tokenization adversarial perturbations, and instruction-data separation. The core is decoupling text syntax from token representation.

    • Indirect prompt injection attacks and evaluation benchmarks:
      • Greshake et al. (2023) and Perez and Ribeiro (2022) — proposed indirect prompt injection forms that hide instructions in retrieved documents or tool outputs read by the model.
      • Liu et al. (2024), BIPIA (Yi et al., 2025), InjecAgent (Zhan et al., 2024), and AgentDojo (Debenedetti et al., 2024) — formalized prompt injection evaluation and built benchmarks, where InjecAgent evaluates single-step tool call hijacking and AgentDojo evaluates multi-turn agent task completion.
      • Nasr et al. (2026) and Jia et al. (2026) — noted that recent defenses often fail under adaptive attacks; the authors accordingly evaluate search attacks against tokenization defenses.
    • Prompt injection research targeting chat templates:
      • ChatBug (Jiang et al., 2025) and Virtual Context (Zhou et al., 2024) — showed that deviating from training templates or inserting special tokens can manipulate models or improve jailbreak effectiveness.
      • ChatInject (Chang et al., 2026) — established high attack success rates for forged templates in agents; its appendix uses Unicode lookalike characters to reduce Qwen3's attack success rate from 54.8% to 17.5%, but because both bytes and token IDs change, the contributions cannot be separated.
      • Ye et al. (2026), Li et al. (2025), and MetaBreak (Zhu et al., 2026) — Ye et al. argue that models infer roles from style rather than specific markers; Li et al. find that perturbing role separators breaks task performance; MetaBreak exploits embedding-space proximity to ordinary tokens to bypass special-token filtering.
    • Adversarial and perturbation work at the tokenizer level:
      • Geh et al. (2025), TokenBreak (Schulz et al., 2025), and Zheng et al. (2025) — study the effect of re-segmenting ordinary subword sequences on model behavior, but the strings they process never have reserved IDs.
      • Deng et al. (2026) — compared reserved versus single-character segmentation on Qwen3-8B and reported no effect; the authors attribute this to a saturation ceiling in the probability metric.
    • Instruction-data separation defenses:
      • Zverev et al. (2025, 2026), Wang et al. (2025), Wallace et al. (2024), and Chen et al. (2025a,b,c) — attempt to isolate instructions from data via positional encodings, instruction-level fine-tuning, and architectural separation, respectively.
      • Cefalu et al. (2024) and Hines et al. (2024) — isolate untrusted data using disjoint token sets or prompt markers, respectively.
    • Baselines and benchmarks: The experimental benchmarks are InjecAgent and AgentDojo; control baselines include default reserved tokenization (Reserved), standard tokenization splitting (Split), ordinary plaintext prompts (Plaintext), and character perturbations.
    • Positioning of this paper: The authors position this work at the server-side tokenizer level, separating the role of reserved control IDs from text appearance while strictly keeping input bytes identical, measuring the authority of reserved representations, and pointing out that existing tokenizer configurations leave tool-protocol token defenses uncovered.
  3. How does the paper address this problem?

    By comparing reserved and subword segmentation under fixed bytes, a token-count compensation control definition is introduced to identify gaps, combined with vector replacement causal intervention and source-aware tokenizers to verify defenses.

    The authors propose a fixed-bytes contrast framework that, while keeping input bytes exactly identical, controls reserved token IDs versus ordinary subword segmentation through server-side tokenization, and combines a token-count compensation control group to quantify the authority of reserved representations.

    Encoding condition design and formalization of the identity gap

    • Core condition comparison: The attacker inserts forged template markers in tool returns. Default tokenization converts them into a single reserved token (Reserved); standard tokenization mitigation (Split) uses the ordinary vocabulary to segment them into subword sequences, with both decoding to strictly identical bytes.
    • Token-count compensation control group (Matched): Splitting markers introduces 7 to 33 extra tokens (Qwen3: 15–17, Llama-3.1: 31–33, GLM-4.5: 7–8, Seed-OSS-36B: 12–13). Matched keeps reserved token IDs unchanged and forces the same number of extra tokens at the beginning of the tool return's ordinary text to isolate the penalty of increased token count.
    • Identity gap definition: Δ = ASR(Matched) − ASR(Split) Equation (1) defines the identity gap Δ, quantifying in percentage points the absolute difference in attack success rate contributed by reserved representations relative to the same text as subwords.
    • Plaintext control (Plaintext): Uses plain-text role labels such as System: instead of template markers to measure the overall advantage of templates over plain text.

    Vector replacement and causal intervention design

    • Length-preserving vector replacement: To avoid token length changes, the Reserved token sequence is kept completely unchanged, and only the input embedding vectors at reserved marker positions are replaced with other vectors (Table 4).
    • Replacement target selection: Tests the mean of the marker's corresponding subword vectors (Mean), the nearest ordinary token vector in embedding space by cosine similarity (Nearest), and other valid reserved control tokens in the same model (Other reserved, e.g., <|endoftext|> for Qwen3, <|python_tag|> for Llama-3.1).
    • Text appearance ablation control: Designs lookalike markers with the same character length but no reserved IDs (Lookalike, e.g., <|zz_end|>) and recased markers (Recased) to quantify the surface term of the marker's plain-text contribution.

    Mechanism probing and tokenization defense construction

    • Instruction tuning and thinking block control: For base and instruction-tuned model pairs, uses forced prefix reading of tool name logit differences; through Qwen3's template parameter enable_thinking, disables the model's implicit thinking block to test the compensatory role of reasoning in text parsing.
    • Source-Aware Encoder: In the tokenization stage, processes trusted and untrusted text spans independently; untrusted spans use a tokenizer copy with special-token matching removed, preserving pre-tokenization and BPE merging logic; for models with reserved IDs in the base vocabulary (e.g., Kimi-K2), constructs a constrained shortest-path lattice encoder.
  4. What experiments did the paper conduct?

    On two benchmarks, the dominant role of reserved token vectors is verified, revealing the compensatory effect of thinking reasoning, defense gaps in tool protocol tokens, and the threat of adaptive embedding search.

    Experimental Setup

    • Models under test: Qwen3-8B, Qwen3-32B, Llama-3.1-8B-Instruct, GLM-4.5 (FP8 precision), Seed-OSS-36B-Instruct, and Qwen3-1.7B for logit comparison.
    • Evaluation benchmarks and sample sizes: InjecAgent sampled 400 direct harm (DH) and 400 data stealing (DS) cases (full analysis uses 510 DH and 543 DS cases); AgentDojo uses 409 pairs (four suites) and 224 pairs (three suites) held-out test sets.
    • Comparison conditions: Reserved (default reserved tokens), Matched (reserved tokens with matched token count), Split (ordinary subword tokenization), Plaintext (plaintext role prompt).
    • Metric definition and judgment: ASR (%) is determined by whether the model's next-turn tool call contains the attacker-specified tool; strict judgment additionally requires all required parameters; AgentDojo success is judged by the safety check after tool execution; the identification gap Δ is measured in percentage points (pp).
    • Service and repetition settings: vLLM greedy decoding with temperature set to 0; each configuration is run 3 to 5 times, with significance established by the Exact McNemar test being significant in every run; token budgets are 1536 for Qwen3, Llama-3.1, and GLM-4.5, and 4096 for Seed-OSS-36B.

    Main Results

    The main results are shown in Table 2 (mean of repeated runs on 400 paired samples per configuration on InjecAgent):

    Swipe horizontally to read the table

    ModelAttack typeReserved (%)Matched (%)Split (%)Plaintext (%)Identification gap Δ (pp)
    Qwen3-8Bdirect harm84.883.475.320.4+8.1
    Qwen3-8Bdata stealing90.990.089.541.6+0.5
    Llama-3.1-8Bdirect harm98.297.839.751.6+58.2
    Llama-3.1-8Bdata stealing99.599.249.153.4+50.2
    GLM-4.5direct harm71.571.111.10.0+60.0
    GLM-4.5data stealing92.392.727.20.8+65.5
    Seed-OSS-36Bdirect harm85.084.826.231.1+58.6
    Seed-OSS-36Bdata stealing76.978.639.357.8+39.3
    • Reserved representation dominates attack success on most models: On Llama-3.1, GLM-4.5, and Seed-OSS-36B, removing reserved tokens reduces ASR by 39.3 to 65.5 percentage points, and the Matched vs. Reserved gap is within 1.7 pp, confirming that the cost of extra token count is near zero.
    • Qwen3-8B exhibits text-appearance dominance: Qwen3-8B has an identification gap of 8.1 pp on direct harm and 0.5 pp on data stealing (not significant), but Split exceeds Plaintext by 54.9 pp and 47.9 pp respectively; the authors state its attacks rely mainly on the marked text itself.

    Vector Localization and Mechanism Analysis

    • A single input vector carries authority: On 510 direct harm cases, after Llama-3.1-8B replaces the reserved marker vector with the nearest ordinary token vector in embedding space, ASR recovers to 98.4% (Reserved is 98.2%), while replacing with the mean subword vector yields only 58.4% (Table 4).
    • Instruction tuning strengthens reserved-token preference: In a teacher-forced logit difference test on 200 cases, the fine-tuned Qwen3-1.7B, Qwen3-8B, and Seed-OSS-36B all significantly prefer reserved tokens (+7.82, +0.68, +0.33 logits respectively), while base models show no preference or an opposite preference (Table 26).
    • Suppressing the thinking block degrades text recognition: After disabling enable_thinking on Qwen3-8B, Split success on direct harm drops from 74.7% to 35.7%, and the identification gap widens from 8.8 pp to 49.8 pp (Table 27); the authors state that without reserved tokens its attacks rely on explicit reasoning to infer the role.

    Multi-Turn Agents and Existing Defense Deficiency Evaluation

    • Identification gap persists at the execution end of multi-turn tasks: On the AgentDojo four-suite 409-pair test set, the execution-level identification gaps for Qwen3-8B and Qwen3-32B are 10.3 pp and 6.8 pp respectively (Table 28); on the 224-pair three-suite test, Llama-3.1 in the banking scenario reduces attack success from 22.5% to 6.7% with Split (Table 29).
    • Tokenization mitigation leaves tool-protocol vulnerabilities: A census of the top 400 dialogue models by Hugging Face downloads found that 33 tokenizer configurations (covering 255 models, 64%) declare tool-protocol tokens as special:false; forging tool blocks using only such tokens yields identification gaps of 9.4 to 19.9 pp across four model types (Table 31).
    • Adaptive search bypasses tokenization defenses: An attacker searches embedding space for non-reserved ordinary tokens to replace forged markers, achieving attack success of 92.2% on Llama-3.1-8B (98.0% undefended) and 70.4% on GLM-4.5 (72.0% undefended); the defense removes only 1.6 to 12.2 pp of success (Table 32).

    Other Ablations and Analyses

    • Extra-token insertion position ablation: inserting extra tokens before or after the marker changes the identification gap within 1.4 to 3.0 pp (Table 22).
    • Single-character tokenization rule comparison: character-level tokenization yields an identification gap of 54.3 pp on Qwen3-8B DH and 37.8 pp on Llama-3.1-8B (Table 21).
    • Reconciling prior null-result studies: Deng et al. (2026)'s probability difference reproduces as a 0.14 pp drop (99.998% to 99.860%) on our data, due to a probability saturation ceiling (Table 24).
    • Forged-role ablation: replacing system with user in the forged block changes the gap within 3 pp for Qwen3-8B and Llama-3.1, and narrows it by 25 pp for GLM-4.5 (Table 19).
    • Inference-engine robustness: re-evaluation with Hugging Face native transformers.generate shows identification gaps within 0.7 to 4.0 pp of vLLM (Table 16).
    • Benign-task utility test: on 57 benign AgentDojo tasks, defended and undefended utility are 69.0% and 64.9% respectively, with no statistically significant difference (Appendix F).
  5. What are some points that can be further explored?

    The authors point out three limitations: the open-source self-hosted scope, the tool-call parsing success criteria, and input-layer interventions; their experiments cover six open-source models and two major evaluation benchmarks.

    Limitations and future directions noted by the authors

    • Only open-source self-hosted models studied: In Section 5, Limitations, the paper notes that the research only covers self-hosted open-weight models where the deployer controls the tokenization process; managed commercial APIs that only accept string inputs are outside the scope of the research.
    • Limitation of benchmark success criteria: Section 5, Limitations, notes that the success criteria on InjecAgent are based on the tool call parsed from the model's next turn, and task-level execution success is only measured on AgentDojo.
    • Vector intervention is not an external attack input: Section 5, Limitations, notes that the vector replacement operation in Section 4.4 directly intervenes in the model's input representation layer and is not bytes an attacker can directly send over the network.
    • Directions for extending defense evaluation: In the conclusion of Section 5, the authors propose that the fixed-byte comparison method could in the future be used to evaluate models specifically trained against prompt injection (such as StruQ, SecAlign, Meta SecAlign), to test whether the defense eliminates representation authority or only eliminates trigger surface features.
    • Call to report defensive mechanisms: In the conclusion of Section 5, the authors propose that template attack research should in the future report specific token IDs alongside the text, and that defense evaluations should be adjudicated based on the token IDs the model actually receives.

    Experimental coverage

    • Scope of tested models: The full-generation evaluation covers 5 models: Qwen3-8B, Qwen3-32B, Llama-3.1-8B-Instruct, GLM-4.5, and Seed-OSS-36B-Instruct; logit probing additionally includes Qwen3-1.7B.
    • Evaluation benchmarks and sample sizes: InjecAgent samples 400 DH and 400 DS cases (full analysis uses 510 DH and 543 DS cases); AgentDojo evaluates 409 pairs (four suites) and 224 pairs (three suites) of held-out test sets.
    • Scope of tokenizer configuration survey: The survey covers the top 400 text-generation conversational models by download count on the Hugging Face Hub, summarized into 67 distinct tokenizer configurations.
    • Adaptive search space: The adaptive attack evaluates 6 preset rules and a search space of 115 to 133 candidate spellings per model.
    • Statement of unreported information: The paper does not report token-level performance on commercial closed-source hosted models (because the tokenizer is a black box and not visible).
  6. Summarize the main content of the paper

    The authority of dialogue template injection mainly comes from the learned vectors of reserved tokens rather than text syntax, reasoning has a compensatory effect, and existing tokenization defenses leave tool protocol vulnerabilities.
    • Core positioning and problem: For the mechanism of effectiveness of dialogue template forgery attacks in large model agents, the paper, under strictly fixed input bytes, is the first to decouple and quantitatively measure the contributions of reserved control token IDs and template text appearance.
    • Core method design: Proposes a fixed-bytes contrast framework that controls reserved tokens versus ordinary subword segmentation through server-side tokenization, and introduces a token-count compensation control group (Matched) to define the identity gap Δ, combined with input embedding layer vector replacement for causal attribution.
    • Key experimental results:
      • On Llama-3.1, GLM-4.5, and Seed-OSS-36B, removing reserved tokens reduces InjecAgent attack success rate by 39.3 to 65.5 percentage points, confirming that reserved representations dominate attack power (Table 2).
      • The authority of reserved markers is rooted in a single learned vector at the marker position; replacing it with the nearest ordinary token vector in embedding space on Llama-3.1-8B recovers 98.4% of the success rate (Table 4).
      • Qwen3-8B exhibits text-syntax-dominant characteristics, but after disabling the thinking block, the attack success rate with reserved tokens removed drops from 74.7% to 35.7%, with the identity gap expanding to 49.8 percentage points (Table 27).
      • A survey found that 64% of mainstream open-source model tokenizers do not cover tool protocol tokens, and adaptive embedding neighbor search can recover most of the attack success rate (Table 31, Table 32).
    • Author conclusions and implications: The authors believe that the authority of dialogue template injection attacks mainly comes from learning signals assigned to reserved control vectors during model post-training; security research and defense deployment must go deep into the tokenizer level and review the specific token IDs passed to the model.

Related papers

Show 3 more papers
Read originalhuggingface.co