Skip to content

fix(chat): use Qwen3 template for Qwen3ChatTemplate.template_str#1492

Open
lntutor wants to merge 1 commit into
guidance-ai:mainfrom
lntutor:fix/qwen3-chat-template-str
Open

fix(chat): use Qwen3 template for Qwen3ChatTemplate.template_str#1492
lntutor wants to merge 1 commit into
guidance-ai:mainfrom
lntutor:fix/qwen3-chat-template-str

Conversation

@lntutor

@lntutor lntutor commented Jul 19, 2026

Copy link
Copy Markdown

What's broken

Qwen3ChatTemplate.template_str is set to qwen2dot5_it_template — a copy-paste from Qwen2dot5ChatTemplate:

class Qwen3ChatTemplate(ChatTemplate):
    template_str = qwen2dot5_it_template   # <-- should be qwen3_it_template

But the class is registered in CHAT_TEMPLATE_CACHE for qwen3_it_template / qwen3_gguf_template. Engine.chat_completion renders the prompt from get_chat_template().template_str, so every Qwen3 chat completion is rendered with the Qwen2.5 template. The two differ materially: with no system message, the Qwen2.5 template injects a spurious default "You are Qwen, created by Alibaba Cloud. You are a helpful assistant.", and it lacks Qwen3's <think>/enable_thinking handling — a silently malformed prompt.

It's the only one of the 12 template classes whose template_str references a template it isn't registered for.

Fix

Point template_str at qwen3_it_template (defined just above the class).

Tests

Adds tests/unit/test_chat.py (chat.py had no offline unit test — existing chat-template tests need a model download): the Qwen3 class's template_str matches its registered template, and rendering a user-only conversation no longer injects the Qwen2.5 default system message. Full offline unit suite passes (428) with no regressions.

Qwen3ChatTemplate.template_str was mistakenly set to qwen2dot5_it_template
(a copy-paste from Qwen2dot5ChatTemplate), even though the class is
registered in CHAT_TEMPLATE_CACHE for qwen3_it_template/qwen3_gguf_template.
Engine.chat_completion renders the prompt from get_chat_template().
template_str, so every Qwen3 chat completion was rendered with the
Qwen2.5 template -- injecting a spurious default 'You are Qwen, created by
Alibaba Cloud...' system message when none is supplied and dropping
Qwen3's <think>/enable_thinking handling.

Point template_str at qwen3_it_template so the rendered prompt matches the
template the class is registered for.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N6RtoHuxrDqTUo9Mw9h4Cv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant