bug: distinguish properties map from schema nodes when stripping unsupported keys for Vertex AI#1697
Open
944750720 wants to merge 1 commit into
Open
Conversation
…cleanup recursivelyDeleteUnsupportedParameters was unconditionally deleting the "title" key at every object level, which also removed legitimate data properties named "title" from the properties map (e.g. MiddleModel.title in nested Pydantic schemas). This caused field loss and broken required references when using deeply nested structured output schemas with Vertex AI. Fix: treat `properties` as a name->schema map and recurse into its values instead of the map itself. Also unify the anyOf/array recursion path and extract an isSchemaNode helper for readability. Ref: googleapis/python-genai#1732 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Gemini's function-calling parser misinterprets
titlefields inside$defsas callable function names, causingMALFORMED_FUNCTION_CALLerrors with nested Pydantic models. This is the same root cause addressed by pydantic/pydantic-ai#3487 and reported in googleapis/python-genai#1732.The gateway already be able to strips
titleviarecursivelyDeleteUnsupportedParameters, but the function had a secondary bug: it treats every object it visits as a schema node and runsdelete obj['title']on it.propertiesis not a schema node — it is a name→schema map whose keys are user-defined field names, not schema keywords. Sodelete obj['title']on apropertiesmap removes an entire field definition whose name happens to betitle, whilerequiredstill references it — producing a broken schema.Fix: when the key is
properties, skip keyword deletion on the map itself and recurse directly into each value (the actual sub-schemas). Also unify anyOf/array recursion and extract anisSchemaNodetype guard for readability.Test plan
recursivelyDeleteUnsupportedParameterscovering root, nested, anyOf, and all unsupported keystitle)utils.test.tspass🤖 Generated with Claude Code