Skip to content

fix(mistral): Validate tool_calls type before iterating#34272

Open
elizabetht wants to merge 4 commits intovllm-project:mainfrom
elizabetht:fix/mistral-tool-calls-validation
Open

fix(mistral): Validate tool_calls type before iterating#34272
elizabetht wants to merge 4 commits intovllm-project:mainfrom
elizabetht:fix/mistral-tool-calls-validation

Conversation

@elizabetht
Copy link
Contributor

@elizabetht elizabetht commented Feb 10, 2026

maybe_serialize_tool_calls() calls next() on the raw tool_calls value without verifying it is an iterable. When tool_calls is a string or other non-iterable type, the pydantic ValidatorIterator tries to validate each character as a dict, producing a confusing error.

Add an explicit type check before iterating: if tool_calls is not a list, tuple, or iterator, raise a clear ValueError. Also skip the message entirely when tool_calls is None instead of creating an empty tuple iterator.

Purpose

Fixes #34225

Test Plan

Test Result


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
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

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

The pull request effectively addresses a critical issue where maybe_serialize_tool_calls could encounter runtime errors when processing tool_calls values that are iterable but not direct iterators (e.g., lists or tuples). The introduction of explicit type checking and proper handling for None values significantly enhances the function's robustness. The new test cases are comprehensive and cover various scenarios, including valid lists, None values, and invalid types like strings and integers, which is excellent for ensuring the fix works as intended.

elizabetht and others added 4 commits February 10, 2026 15:04
maybe_serialize_tool_calls() calls next() on the raw tool_calls value
without verifying it is an iterable. When tool_calls is a string or
other non-iterable type, the pydantic ValidatorIterator tries to
validate each character as a dict, producing a confusing error.

Add an explicit type check before iterating: if tool_calls is not a
list, tuple, or iterator, raise a clear ValueError. Also skip the
message entirely when tool_calls is None instead of creating an
empty tuple iterator.

Signed-off-by: Elizabeth Thomas <[email protected]>
Signed-off-by: Reagan Lee <“[email protected]”>
Co-authored-by: Reagan Lee <“[email protected]”>
Signed-off-by: Elizabeth Thomas <[email protected]>
Signed-off-by: Jarno Seppänen <[email protected]>
Co-authored-by: Tyler Michael Smith <[email protected]>
Signed-off-by: Elizabeth Thomas <[email protected]>
…ls_validator

The current implementation assigns raw_tool_calls directly to
tool_calls_validator. If raw_tool_calls is a list or tuple (which are
iterable but not iterators), calling next() will raise a TypeError.

Explicitly convert lists/tuples using iter() to ensure
tool_calls_validator is always an actual iterator before next() is called.

Signed-off-by: Elizabeth Thomas <[email protected]>
@elizabetht elizabetht force-pushed the fix/mistral-tool-calls-validation branch from d2fbee7 to 03f69e9 Compare February 10, 2026 21:04
@juliendenize
Copy link
Contributor

juliendenize commented Feb 12, 2026

Hey thanks for contributing, i think the issue is just having a proper error message, i did this pr that should fix it and is a bit less verbose
#34438

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

4 participants