fix(google): keep tool argument defaults in the Gemini schema - #7190
Open
Darshak03 wants to merge 1 commit into
Open
fix(google): keep tool argument defaults in the Gemini schema#7190Darshak03 wants to merge 1 commit into
Darshak03 wants to merge 1 commit into
Conversation
_GeminiJsonSchema._simplify dropped `default` from every property. types.Schema supports the field, so unlike `title` or `$schema` this removed information Gemini accepts and uses: for a pre-filled argument the default is the model's only record of the value, so the model omitted the argument and the tool rejected the call. Fixes livekit#7189
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.
_GeminiJsonSchema._simplifydroppeddefaultfrom every property of a tool's JSON Schema:google.genai.types.Schemahas adefaultfield, so unliketitleor$schemathis is not compatibility stripping — it removes information Gemini accepts and uses. For an argument the caller pre-filled, that default is the model's only record of the value: with it gone the model omits the argument, and a tool that needs it (an MCP server expectingautomationId/version, say) rejects the call with an invalid-arguments error.Both paths through
_GeminiJsonSchemaare affected — thechat()LLM path, and the realtime path, which is routed throughsimplify()for raw-schema function tools because Gemini Live does not acceptparameters_json_schema(#5560, googleapis/python-genai#1147).Tests:
test_default_is_keptasserts the defaults survive and round-trips the result throughtypes.Schema, so the kept value is proven acceptable to the genai type. Two existing expectations are updated to keep the defaults they previously asserted were stripped.A nullable field (
Location | None = None) now keeps"default": None. That is left as-is rather than filtered: it is the schema as declared, and it serializes away.schema.pop("default", None)has been there since #1588 and looks carried over from the pydantic-ai implementation this class is based on, alongside the keywords Gemini genuinely rejects.Fixes #7189