Fix JSON schema generation for complex tool arguments#317
Open
rakeshutekar wants to merge 1 commit into
Open
Conversation
Use Pydantic JSON Schema output for callable tool parameters so annotations like list[str], dict[str, int], and optionals do not fall back to invalid stringified JSON Schema types.
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.
Summary
Fix callable tool schema generation so complex Python annotations emit valid JSON Schema instead of stringified Python types.
Problem
Tools._convert_to_tool_spec()manually mapped only primitive types and fell back tostr(field_type)for everything else. For annotations likelist[str],dict[str, int], orint | None, this produced invalid JSON Schema types such as"list[str]".Changes
model_json_schema()for callable tool parameter schemas$defsreferencestitlefieldsTest Plan
Results:
tests/utils/test_tool_manager.py: 8 passedtests/utils/test_tools_mcp_schema.py: 12 passedtests/client/test_manual_tool_calling.py: 4 passed