-
-
Notifications
You must be signed in to change notification settings - Fork 12k
[Bugfix] Add validation for tool requests when tool_parser is unavailable #30613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Bugfix] Add validation for tool requests when tool_parser is unavailable #30613
Conversation
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run You ask your reviewers to trigger select CI tests on top of Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. 🚀 |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly addresses a bug where vLLM would fail silently when tool choice was required but the tool parser was not enabled. The added validation ensures a clear error message is returned to the user, improving the developer experience. The new logic is covered by a unit test. I have one suggestion to refactor the validation logic to improve maintainability by reducing code duplication.
| if ( | ||
| request.tool_choice is not None | ||
| and request.tool_choice not in ("none", "auto") | ||
| and tool_parser is None | ||
| and not isinstance(tokenizer, MistralTokenizer) | ||
| and not self.use_harmony | ||
| ): | ||
| return self.create_error_response( | ||
| f'tool_choice="{request.tool_choice}" requires ' | ||
| "--enable-auto-tool-choice and --tool-call-parser to be set" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This validation logic duplicates the condition from the tool_choice='auto' check on lines 207-212. This could lead to maintenance issues if the conditions for tool parsing availability change in the future.
Consider refactoring to centralize the check. You could define a tool_parsing_unavailable variable and then use a single if block to handle all tool_choice values that require a parser ('auto', 'required', and named tools).
Example refactoring for lines 207-232:
tool_parsing_unavailable = (tool_parser is None and
not isinstance(tokenizer, MistralTokenizer) and
not self.use_harmony)
if tool_parsing_unavailable and request.tool_choice not in (None, "none"):
if request.tool_choice == "auto":
return self.create_error_response(
'"auto" tool choice requires '
"--enable-auto-tool-choice and --tool-call-parser to be set")
else:
return self.create_error_response(
f'tool_choice="{request.tool_choice}" requires '
"--enable-auto-tool-choice and --tool-call-parser to be set")Since this refactoring touches lines outside the current diff, I'm providing it as a code block in the comment body.
1d62417 to
b849c5c
Compare
DarkLight1337
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for improving the UX!
|
Done, thanks for the suggestion! |
Head branch was pushed to by a user without write access
b7363a6 to
7909101
Compare
|
PTAL at the failing test |
Head branch was pushed to by a user without write access
|
Hi @majiayu000, the pre-commit checks have failed. Please run: uv pip install pre-commit
pre-commit install
pre-commit run --all-filesThen, commit the changes and push to your branch. For future commits, Tip Is
|
Head branch was pushed to by a user without write access
0c735be to
07228fa
Compare
|
Documentation preview: https://vllm--30613.org.readthedocs.build/en/30613/ |
07228fa to
07f494e
Compare
…able When tool_choice is "required" or a named tool, but the server was not started with --enable-auto-tool-choice and --tool-call-parser, vLLM would silently degrade instead of returning an error. This fix adds validation to return a clear error message indicating that these flags are required for tool parsing. Fixes vllm-project#29432 Signed-off-by: majiayu000 <[email protected]>
Address @DarkLight1337's review comment: for "required" or named tool_choice, only --tool-call-parser is needed (--enable-auto-tool-choice is specific to tool_choice="auto"). Signed-off-by: majiayu000 <[email protected]> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
e9ab033 to
0b43645
Compare
Summary
When
tool_choiceis set to"required"or a named tool (e.g.,{"type": "function", "function": {"name": "get_weather"}}), but the server was not started with--enable-auto-tool-choiceand--tool-call-parser, vLLM would silently degrade instead of returning a clear error.This PR adds validation to return an appropriate error message indicating that these flags are required for tool parsing.
Changes
serving_chat.pyto check iftool_parseris available whentool_choicerequires tool parsingtool_choice="required"and named tool scenariosTest Plan
test_tool_choice_validation_without_parser--enable-auto-tool-choiceFixes #29432