fix: unwrap single-variant anyOf to preserve sibling fields in Vertex AI schema#19270
Open
VedantMadane wants to merge 1 commit intoBerriAI:mainfrom
Open
fix: unwrap single-variant anyOf to preserve sibling fields in Vertex AI schema#19270VedantMadane wants to merge 1 commit intoBerriAI:mainfrom
VedantMadane wants to merge 1 commit intoBerriAI:mainfrom
Conversation
… AI schema Fixes BerriAI#19255 When Pydantic generates Optional[X], it creates: anyOf: [{X schema}, {type: null}] with constraints (default, examples, pattern) as siblings. After convert_anyof_null_to_nullable removes the null type, if only ONE variant remains, we now unwrap it and merge the sibling fields. This prevents _filter_anyof_fields from stripping them. Before: {anyOf: [{type: int, nullable: true}], default: None, examples: [...]} -> {anyOf: [{type: int, nullable: true}]} (siblings lost!) After: {anyOf: [{type: int, nullable: true}], default: None, examples: [...]} -> {type: int, nullable: true, default: None, examples: [...]} Added test: test_anyof_conversion_preserves_sibling_fields Updated tests: test_basic_anyof_conversion, test_build_vertex_schema, test_build_vertex_schema_empty_properties
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Relevant issues
Fixes #19255
Summary
When Pydantic generates
Optional[X], it creates:{ "anyOf": [{"type": "integer", "minimum": 0}, {"type": "null"}], "default": null, "examples": [7, 30, 90], "description": "Filter by number of days" }The constraints (
default,examples,pattern) are siblings ofanyOf.After
convert_anyof_null_to_nullableremoves the null type, if only ONE variant remains inanyOf, we now unwrap it and merge the sibling fields. This prevents_filter_anyof_fieldsfrom stripping them.Before (sibling fields lost):
{"anyOf": [{"type": "integer", "minimum": 0}], "default": null, "examples": [...]} -> {"anyOf": [{"type": "integer", "minimum": 0, "nullable": true}]} // default and examples are LOST!After (sibling fields preserved):
{"anyOf": [{"type": "integer", "minimum": 0}], "default": null, "examples": [...]} -> {"type": "integer", "minimum": 0, "nullable": true, "default": null, "examples": [...]}Pre-Submission checklist
tests/litellm/directory - Addedtest_anyof_conversion_preserves_sibling_fieldsChanges
litellm/llms/vertex_ai/common_utils.py:convert_anyof_null_to_nullableto unwrap single-variant anyOf arrays and merge sibling fieldstests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py:test_anyof_conversion_preserves_sibling_fieldsto verify the fixtest_basic_anyof_conversionto expect unwrapped single-variant anyOftest_build_vertex_schemaandtest_build_vertex_schema_empty_propertiesto reflect new behavior