Is this a bug in chat template?
Hi
I am reading this
https://huggingface.co/learn/smol-course/unit1/2#chat-templates-with-tools
I feel like there is a bug in HuggingFaceTB/SmolLM3-3B 's chat template
from the example
# Conversation with tool usage
messages = [
{"role": "system", "content": "You are a helpful assistant with access to tools."},
{"role": "user", "content": "What's the weather like in Paris?"},
{
"role": "assistant",
"content": "I'll check the weather in Paris for you.",
"tool_calls": [
{
"id": "call_1",
"type": "function",
"function": {
"name": "get_weather",
"arguments": '{"location": "Paris, France", "unit": "celsius"}'
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_1",
"content": '{"temperature": 22, "condition": "sunny", "humidity": 60}'
},
{
"role": "assistant",
"content": "The weather in Paris is currently sunny with a temperature of 22°C and 60% humidity. It's a beautiful day!"
}
]
# Apply chat template with tools
formatted_with_tools = tokenizer.apply_chat_template(
messages,
tools=tools,
tokenize=False,
add_generation_prompt=False
)
print("Chat template with tools:")
print(formatted_with_tools)
I got this result
Chat template with tools:
<|im_start|>system
## Metadata
Knowledge Cutoff Date: June 2025
Today Date: 27 September 2025
Reasoning Mode: /think
## Custom Instructions
You are a helpful assistant with access to tools.
### Tools
You may call one or more functions to assist with the user query.
You are provided with function signatures within <tools></tools> XML tags:
<tools>
{'type': 'function', 'function': {'name': 'get_weather', 'description': 'Get the current weather for a location', 'parameters': {'type': 'object', 'properties': {'location': {'type': 'string', 'description': 'The city and state, e.g. San Francisco, CA'}, 'unit': {'type': 'string', 'enum': ['celsius', 'fahrenheit'], 'description': 'The temperature unit'}}, 'required': ['location']}}}
{'type': 'function', 'function': {'name': 'calculate', 'description': 'Perform mathematical calculations', 'parameters': {'type': 'object', 'properties': {'expression': {'type': 'string', 'description': 'Mathematical expression to evaluate'}}, 'required': ['expression']}}}
</tools>
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
<|im_end|>
<|im_start|>user
What's the weather like in Paris?<|im_end|>
<|im_start|>assistant
I'll check the weather in Paris for you.<|im_end|>
<|im_start|>user
{"temperature": 22, "condition": "sunny", "humidity": 60}<|im_end|>
<|im_start|>assistant
The weather in Paris is currently sunny with a temperature of 22°C and 60% humidity. It's a beautiful day!<|im_end|>
Which is kind of weird.
The first thing is there is no tool call in below message
<|im_start|>assistant
I'll check the weather in Paris for you.<|im_end|>
I expect it to have <tool_call> ... </tool_call> in it.
the second thing is why the tool role got replace with user role.
Should not we explicitly specify the role?
Can someone help me with this, please?
I've noticed this as well with my own LLM inference implementation (PasLLM, not public yet). SmolLM3 seems to omit the <tool_call> XML tags, outputting only the tool call JSON itself without the surrounding <tool_call> and </tool_call> tags, which prevents the tool calls from being executed at the end.