Fix #7203 - Preserve type info for non-object schemas in json_to_pydantic#7862
Open
Whning0513 wants to merge 1 commit into
Open
Fix #7203 - Preserve type info for non-object schemas in json_to_pydantic#7862Whning0513 wants to merge 1 commit into
Whning0513 wants to merge 1 commit into
Conversation
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.
schema_to_pydantic_model loses $defs type information (array -> object)
When converting a JSON schema generated by Pydantic v2 using
schema_to_pydantic_model, type information inside$defsis not preserved. Array types (e.g.,{"type": "array", "items": {"type": "string"}}) get converted to empty objects ({"type": "object", "properties": {}}), breaking the schema round-trip.Reported by: Momo-Not-Emo
The
_json_to_pydantic.pyutility'sschema_to_pydantic_modelfunction recursively converts JSON schemas to Pydantic models. When processing$defsentries, it assumed all definitions were object schemas and created Pydantic models for them, losing type information for non-object types (arrays, unions, literals, etc.).File:
python/packages/autogen-core/src/autogen_core/utils/_json_to_pydantic.py$defs$refresolution to ensure defs are correctly referencedMedium - The change modifies schema-to-Pydantic conversion logic which is used by structured output features. While it fixes a correctness bug, care was taken to maintain backward compatibility for object schemas. Non-object type definitions that were previously silently corrupted will now produce correct types.