Skip to content

Add explicit validation error for tool calls.#34438

Open
juliendenize wants to merge 2 commits intovllm-project:mainfrom
juliendenize:tool_valls_err_msg
Open

Add explicit validation error for tool calls.#34438
juliendenize wants to merge 2 commits intovllm-project:mainfrom
juliendenize:tool_valls_err_msg

Conversation

@juliendenize
Copy link
Contributor

@juliendenize juliendenize commented Feb 12, 2026

Purpose

Add explicit validation error for tool calls.

Fix #34225

Test Plan

Checked with these messages in the request:

    {
        "role": "user",
        "content": [
            {
                "type": "text",
                "text": "Hey call a tool",
            },
        ],
    },
    {
      "role":"assistant",
      "content":"...",
      "tool_calls":"should_be_serialized_object_but_its_str"
    },
    {
        "role": "user",
        "content": [
            {
                "type": "text",
                "text": "What is the weather in Paris?",
            },
        ],
    },
]

Test Result

Raised correctly:

(APIServer pid=106559) ERROR 02-12 14:55:36 [serving.py:310]   File "/mnt/vast/home/julien.denize/workspace/vllm/vllm/tokenizers/mistral.py", line 77, in maybe_serialize_tool_calls
(APIServer pid=106559) ERROR 02-12 14:55:36 [serving.py:310]     raise ValueError(
(APIServer pid=106559) ERROR 02-12 14:55:36 [serving.py:310]     ...<2 lines>...
(APIServer pid=106559) ERROR 02-12 14:55:36 [serving.py:310]     ) from e
(APIServer pid=106559) ERROR 02-12 14:55:36 [serving.py:310] ValueError: Validating messages' `tool_calls` raised an error. Please ensure `tool_calls` are iterable of tool calls.

Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results

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 introduces an explicit validation error for tool_calls to improve error handling when invalid data is provided. The change correctly catches pydantic.ValidationError and raises a more user-friendly ValueError. I've suggested a refactoring to make the implementation more concise and Pythonic by using list() to consume the iterator, which simplifies the code while maintaining the same logic.

Signed-off-by: juliendenize <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: maybe_serialize_tool_calls() fails to verify the tool_calls type

2 participants