fix(tools/mcp): preserve inline object properties in create_model_from_json_schema (#22141)#22145
Open
C1-BA-B1-F3 wants to merge 1 commit into
Open
Conversation
…m_json_schema (run-llama#22141) Inline object schemas (type: object with properties) were previously falling through to Dict[str, Any] which discarded the declared properties and their types. The LLM/agent would then see a generic dict instead of structured nested fields. This fix: - Detects inline objects via _is_object_with_properties() - Creates Pydantic sub-models for them via _create_inline_object_model() - Generates stable model names via _get_inline_model_name() - Threads field_name/parent_model_name through the resolution chain so nested models get meaningful names and recursion works Fixes: run-llama#22141
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.
Description
Inline object schemas (
"type": "object"with"properties") in MCP tool input schemas were being silently converted toDict[str, Any], which discarded the declared properties and their types. This meant the LLM would see a generic dict instead of structured nested fields, making it impossible for the agent to correctly populate nested object parameters.Root Cause
In
_resolve_basic_type(), objects withoutadditionalPropertiesfell through to thejson_type_mappingfallback (object→Dict[str, Any]), losing all declared properties.Changes
tool_spec_mixins.py_is_object_with_properties()— detects inline object schemas (type=object with properties)_create_inline_object_model()— creates a Pydantic sub-model for each inline object_get_inline_model_name()— builds stable, human-readable model names using parent model and field name contextfield_nameandparent_model_namethrough_resolve_field_type→_resolve_basic_type→_create_list_type/_resolve_union_type/_resolve_union_option→_create_inline_object_modelchain, enabling recursive nested object handlingbase.pymodel_nameto_extract_fields()so inline models get meaningful namesTest
test_create_model_from_json_schema_preserves_nested_inline_object— verifies nested object schemas produce proper Pydantic models with correct types, required fields, and validationEdge Cases Verified
Closes #22141