fix: respect tool_choice="none" by excluding tools from template#210
Open
awanawana wants to merge 1 commit intowaybarrios:mainfrom
Open
fix: respect tool_choice="none" by excluding tools from template#210awanawana wants to merge 1 commit intowaybarrios:mainfrom
awanawana wants to merge 1 commit intowaybarrios:mainfrom
Conversation
When tool_choice is set to "none", models like Qwen2.5 and Llama 3.x still activate their tool-calling behavior if tools are present in the chat template context (even with an empty list). This causes the model to output tool_calls with empty arguments instead of normal text content. The fix checks tool_choice before passing tools to the chat template. When tool_choice="none", tools are not included in chat_kwargs, preventing the template from activating tool-calling mode. Fixes waybarrios#162 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This was referenced Mar 24, 2026
Collaborator
|
Note: our PR #173 takes a more complete approach to The two fixes are complementary but independent: template stripping prevents the model from seeing tool definitions, parser suppression prevents false-positive tool call extraction from generated text. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #162
When
tool_choiceis set to"none", models like Qwen2.5-Instruct and Llama 3.x-Instruct still activate their tool-calling behavior if tools are present in the chat template context. This causes:finish_reason: "tool_calls"instead of"stop"content: nullwith tool_calls containing empty{}argumentsRoot Cause
The chat completions handler was passing
toolstochat_kwargswithout checkingtool_choice. Even withtool_choice="none", if tools were present in the request, they would be passed toapply_chat_template(). Qwen2.5 and Llama 3.x have tool-calling jinja templates that activate when atoolskey is present — even an empty list triggers this behavior.Solution
Before adding tools to
chat_kwargs, check iftool_choice == "none". If so, skip adding tools entirely. This prevents the template from activating tool-calling mode.This matches the behavior of upstream vLLM's
--exclude-tools-when-tool-choice-noneflag.Test Plan
🤖 Generated with Claude Code