fix(py): Fix code execution serialization issue for googleai plugin#5326
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors configuration normalization in the Gemini plugin to ensure camelCase aliases are correctly mapped to canonical snake_case fields. It introduces a _pick_plugin_schema method to select the appropriate schema based on input keys. Review feedback identifies a potential regression for Gemma models because the logic defaults to GeminiConfigSchema, which has stricter validation than GemmaConfigSchema; the reviewer suggests dynamically selecting the schema based on the model version.
MichaelDoyle
approved these changes
May 14, 2026
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.
Fixes the bug bash entry where
ai.generate(config=GeminiConfigSchema(...).model_dump())withcode_execution: Trueraised:ValidationError for GenerateContentConfig
codeExecution: Extra inputs are not permitted [type=extra_forbidden]
Root cause: when a request reaches the Gemini plugin, request.config is typed as the generic
GenerationCommonConfig, which stores plugin-specific keys verbatim onmodel_extra(typically alias-form / camelCase). The plugin's_normalize_config_to_dicthad a branch that just trusted the base type and dumped it without re-routing throughGeminiConfigSchema, so the camelCase extra leaked past the snake_casepop()in_extract_tools_from_configand ended up at the SDK's strictGenerateContentConfig(extra='forbid').Fix: always re-validate non-plugin inputs through the plugin schema before dumping. Pydantic's
populate_by_name=Trueon the plugin schema folds aliased extras onto their canonical snake_case fields. As a side benefit, this fixes the same latent issue for every other aliased Gemini-only field (googleSearchRetrieval, urlContext, fileSearch, functionCallingConfig, safetySettings, apiKey, contextCache, etc.).Refactor: extracted
_pick_plugin_schemaso the routing-by-marker-key logic isn't inlined; the main function now reads as a single top-to-bottom flow.Tests: 4 parametrized normalize-canonicalization cases (all 3 input shapes + a fast-path GeminiConfigSchema instance) and 1 e2e test that runs
_genkit_to_googleai_cfgon the original repro shape and asserts the convenience flag was translated into a Tool(code_execution=...) with no leftover camelCase keys on the SDK config.Branch: main (apply on top of origin/main).
Preflight: ruff format/check, ty/pyrefly/pyright, pytest 3.10-3.14 -- all green.