Skip to content

Conversation

@majiayu000
Copy link
Contributor

Summary

When tool_choice is 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-choice and --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

  • Added validation in serving_chat.py to check if tool_parser is available when tool_choice requires tool parsing
  • Added test case covering both tool_choice="required" and named tool scenarios

Test Plan

  • Added unit test test_tool_choice_validation_without_parser
  • Test verifies error response contains guidance about --enable-auto-tool-choice

Fixes #29432

@github-actions
Copy link

👋 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 fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors.

You ask your reviewers to trigger select CI tests on top of fastcheck CI.

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 ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

🚀

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@mergify mergify bot added the frontend label Dec 13, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines 222 to 232
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"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

@majiayu000 majiayu000 force-pushed the fix/validate-tool-requests-29432 branch from 1d62417 to b849c5c Compare December 13, 2025 15:20
Copy link
Member

@DarkLight1337 DarkLight1337 left a 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!

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) December 14, 2025 04:09
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Dec 14, 2025
@majiayu000
Copy link
Contributor Author

Done, thanks for the suggestion!

auto-merge was automatically disabled December 14, 2025 04:24

Head branch was pushed to by a user without write access

@majiayu000 majiayu000 force-pushed the fix/validate-tool-requests-29432 branch from b7363a6 to 7909101 Compare December 14, 2025 04:24
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) December 14, 2025 04:44
@DarkLight1337
Copy link
Member

PTAL at the failing test

auto-merge was automatically disabled December 14, 2025 07:46

Head branch was pushed to by a user without write access

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) December 14, 2025 07:49
@mergify
Copy link

mergify bot commented Dec 14, 2025

Hi @majiayu000, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy or markdownlint failing?
mypy and markdownlint are run differently in CI. If the failure is related to either of these checks, please use the following commands to run them locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10
# For markdownlint
pre-commit run --hook-stage manual markdownlint

auto-merge was automatically disabled December 14, 2025 08:02

Head branch was pushed to by a user without write access

@majiayu000 majiayu000 force-pushed the fix/validate-tool-requests-29432 branch 2 times, most recently from 0c735be to 07228fa Compare December 14, 2025 08:09
@mergify
Copy link

mergify bot commented Dec 14, 2025

Documentation preview: https://vllm--30613.org.readthedocs.build/en/30613/

majiayu000 and others added 2 commits December 17, 2025 10:46
…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]>
@majiayu000 majiayu000 force-pushed the fix/validate-tool-requests-29432 branch from e9ab033 to 0b43645 Compare December 17, 2025 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation frontend ready ONLY add when PR is ready to merge/full CI is needed

Projects

Status: Ready
Status: No status

Development

Successfully merging this pull request may close these issues.

[Bug]: Add validation for tool requests that the tool is available

2 participants