Skip to content

bug: distinguish properties map from schema nodes when stripping unsupported keys for Vertex AI#1697

Open
944750720 wants to merge 1 commit into
Portkey-AI:mainfrom
944750720:fix/vertex-ai-preserve-title-property
Open

bug: distinguish properties map from schema nodes when stripping unsupported keys for Vertex AI#1697
944750720 wants to merge 1 commit into
Portkey-AI:mainfrom
944750720:fix/vertex-ai-preserve-title-property

Conversation

@944750720

@944750720 944750720 commented Jun 20, 2026

Copy link
Copy Markdown

Summary

Gemini's function-calling parser misinterprets title fields inside $defs as callable function names, causing MALFORMED_FUNCTION_CALL errors 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 title via recursivelyDeleteUnsupportedParameters, but the function had a secondary bug: it treats every object it visits as a schema node and runs delete obj['title'] on it. properties is not a schema node — it is a name→schema map whose keys are user-defined field names, not schema keywords. So delete obj['title'] on a properties map removes an entire field definition whose name happens to be title, while required still 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 an isSchemaNode type guard for readability.

Test plan

  • Added unit tests for recursivelyDeleteUnsupportedParameters covering root, nested, anyOf, and all unsupported keys
  • Added regression test reproducing the python-genai#1732 scenario (3-level nested schema where a data field is literally named title)
  • All 23 tests in utils.test.ts pass
  • Prettier formatting verified

🤖 Generated with Claude Code

…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>
@944750720 944750720 changed the title bug: preserve schema properties named "title" in Vertex AI parameter cleanup bug: avoid removing data properties named "title" when stripping unsupported schema metadata Jun 20, 2026
@944750720 944750720 changed the title bug: avoid removing data properties named "title" when stripping unsupported schema metadata bug: distinguish properties map from schema nodes when stripping unsupported keys for Vertex AI Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant