Qwen-3 Chat Template Analysis

Qwen-3 introduces a flexible and efficient chat template

The Qwen-3 model by Qwen features a more sophisticated chat template than its predecessors, Qwen-2.5 and QwQ. This updated Jinja template introduces critical improvements in how the model handles reasoning, manages conversation context, and interacts with tools, making agentic workflows more reliable and efficient.

Optional reasoning via the enable_thinking flag

Qwen-3 allows users to toggle reasoning capabilities using an enable_thinking flag, moving away from the forced chain-of-thought patterns seen in earlier models.

When enable_thinking is set to false, the template inserts an empty <think></think> pair, which signals the model to skip step-by-step thoughts. In contrast, models like QwQ force reasoning in every conversation by baking the <think> tag directly into the generation prompt. If the flag is set to true, the model retains the autonomy to decide whether to engage in reasoning or not.

Dynamic context management with rolling checkpoints

Qwen-3 utilizes a "rolling checkpoint" system to intelligently preserve or prune reasoning blocks based on the conversation's progress. This system traverses the message list in reverse to identify the most recent user turn that was not a tool call. The template preserves full <think> blocks for all assistant replies following that index, while stripping them out for earlier messages.

This dynamic approach provides several technical advantages:

  • Active plan preservation: The model keeps its current plan visible during multi-step tool calls.
  • Nested workflow support: It maintains context for nested tool workflows without loss of information.
  • Token efficiency: It saves tokens by removing reasoning blocks the model no longer requires.
  • Noise reduction: It prevents "stale" reasoning from interfering with new tasks.

Improved tool argument serialization

Qwen-3 improves the reliability of tool calls by implementing a type-check for tool arguments to prevent double-escaping. Previously, in models like Qwen-2.5, every tool_call.arguments field was passed through a | tojson filter regardless of whether the input was already a JSON-encoded string. Qwen-3 now checks if the arguments are already a string; if so, it outputs them directly, and only applies | tojson if the input is not a string.

Removal of the default system prompt

Unlike the Qwen-2.5 series, which used a default system prompt (e.g., "You are Qwen, created by Alibaba Cloud. You are a helpful assistant"), Qwen-3 and QwQ ship without a default system prompt. Despite this omission, the models maintain the ability to accurately identify their creator when asked by the user.

Sources