fix(mistral): Validate tool_calls type before iterating#34272
Open
elizabetht wants to merge 4 commits intovllm-project:mainfrom
Open
fix(mistral): Validate tool_calls type before iterating#34272elizabetht wants to merge 4 commits intovllm-project:mainfrom
elizabetht wants to merge 4 commits intovllm-project:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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.
7237384 to
d2fbee7
Compare
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]>
d2fbee7 to
03f69e9
Compare
Contributor
|
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 |
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.
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
supported_models.mdandexamplesfor a new model.