-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Description
Prerequisites
- I am running the latest code. Mention the version if possible as well.
- I carefully followed the README.md.
- I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
- I reviewed the Discussions, and have a new and useful enhancement to share.
Feature Description
Here is a short explanation of the differences between the chat templates for Qwen3-Coder and Qwen3-Instruct, with clear examples.
The primary difference is how they format tool calls:
- Qwen3-Coder uses a completely custom XML format for both defining and calling tools.
- Qwen3-Instruct uses standard JSON for tool definitions and expects JSON output from the model, wrapped in a simple
<tool_call>
tag.
1. Qwen3-Coder Template (Custom XML Format)
This template instructs the model to generate tool calls using unique XML tags for the function name and each parameter [2]. This format is not standard and requires a special parser to convert the XML into a usable JSON object [3].
Example Tool Call Output:
<tool_call>
<function=search_products>
<parameter=query>
waterproof running shoes
</parameter>
<parameter=sort_by>
price_low_to_high
</parameter>
</function>
</tool_call>
Key Takeaway: The entire call is structured with custom XML tags like <function=...>
and <parameter=...>
[2]. This is why it fails in systems that expect JSON, causing parsing errors [1].
2. Qwen3-Instruct Template (JSON in XML Format)
This template provides the tool definitions to the model as standard JSON. It then instructs the model to respond with a JSON object containing the function name and arguments, all inside a simple <tool_call>
wrapper [4].
Example Tool Call Output:
<tool_call>
{"name": "search_products", "arguments": {"query": "waterproof running shoes", "sort_by": "price_low_to_high"}}
</tool_call>
Motivation
Well, don't we want native tool call support for coder models?
Possible Implementation
https://huggingface.co/Qwen/Qwen3-Coder-30B-A3B-Instruct/blob/main/qwen3coder_tool_parser.py
They have a custom parser that converts the model output to JSON.