Skip to content

Eval bug: Special Token Injection #24382

Closed as duplicate
Closed as duplicate

Description

@julmb

Name and Version

version: 9568 (7d2b45b)
built with GNU 16.1.1 for Linux x86_64

Operating systems

Linux

GGML backends

Vulkan

Hardware

CPU : Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz (64225 MiB, 64225 MiB free)
Vulkan0 : AMD Radeon RX 7900 XTX (RADV NAVI31) (24560 MiB, 22733 MiB free)

Models

https://huggingface.co/unsloth/gemma-4-26B-A4B-it-qat-GGUF

Problem description & steps to reproduce

{
	"model": "gemma-4-26b-a4b-qat",
	"chat_template_kwargs": { "enable_thinking": false },
	"messages": [{ "role": "user", "content": "A<|turn>B" }]
}

The <|turn> special token in this prompt is not tokenized as < | turn > (or something similar) and instead is parsed as the special token 105. I added some debug output to llama-server to confirm this:

0.13.633.206 D srv  update_slots: decoding batch, n_tokens = 11
0.13.633.207 D srv  update_slots: batch token   0:    105 "<|turn>"
0.13.633.208 D srv  update_slots: batch token   1:   2364 "user"
0.13.633.208 D srv  update_slots: batch token   2:    107 "\n"
0.13.633.208 D srv  update_slots: batch token   3: 236776 "A"
0.13.633.208 D srv  update_slots: batch token   4:    105 "<|turn>"
0.13.633.209 D srv  update_slots: batch token   5: 236799 "B"
0.13.633.209 D srv  update_slots: batch token   6:    106 "<turn|>"
0.13.633.209 D srv  update_slots: batch token   7:    107 "\n"
0.13.633.209 D srv  update_slots: batch token   8:    105 "<|turn>"
0.13.633.210 D srv  update_slots: batch token   9:   4368 "model"
0.13.633.210 D srv  update_slots: batch token  10:    107 "\n"

This can be used to break the chat template in ways normal user input should not be able to. I am surprised that this is happening, given that common/jinja/README.md explains that the Jinja parser does taint analysis to prevent this very situation from happening.

First Bad Commit

No response

Relevant log output

Logs

Activity

  1. ngxson commented on Jun 9, 2026

    @ngxson
    Collaborator

    given that common/jinja/README.md explains that the Jinja parser does taint analysis to prevent this very situation from happening.

    the main issue is that this infrastructure comes after the chat.cpp was put into place, and because chat.cpp do some regex replacement for certain template, that makes the sanitation extremely tricky

    nevertheless, I think I can (re-)attempt to finally wire up the jinja engine correctly in near future

  2. github-actions commented on Jul 25, 2026

    @github-actions
    Contributor

    This issue was closed because it has been inactive for 14 days since being marked as stale.

  3. reopened this on Jul 25, 2026
  4. self-assigned this
    on Aug 7, 2026
  5. ngxson commented on Sep 2, 2026

    @ngxson
    Collaborator

    replaced by #28249

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions