Skip to content

fix(py/google-genai)!: strict nested Gemini and Veo config; google_search replaces google_search_retrieval - #6593

Merged
huangjeff5 merged 11 commits into
fix/py-model-config-any-modelfrom
fix/py-gemini-config-strict
Oct 8, 2026
Merged

huangjeff5 merged 11 commits into
fix/py-model-config-any-modelfrom
fix/py-gemini-config-strict

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Nested Gemini settings and VeoConfig reject unknown keys before the request. Each nested setting declares exactly the fields of the google-genai type it is sent as, so an SDK field never fails the check. google_search replaces google_search_retrieval. A Veo API key in config or extra points at context.secrets instead of riding into the request body. Top-level unknown keys on GeminiConfig already raise on #6587. Interactions Lyria strictness is in #6646.

await ai.generate(
    model='googleai/gemini-2.5-flash',
    prompt='hi',
    config={'thinking_config': {'thinking_budjet': 512}},
)
# before: reached the SDK; budget ignored
# after: GenkitError INVALID_ARGUMENT naming thinking_config.thinking_budjet

await ai.generate(model='googleai/gemini-2.5-flash', prompt='hi', config={'google_search': True})
# => search tool attached; google_search=False attaches nothing

await ai.generate_operation(model='googleai/veo-3.0-generate-001', prompt='a fox', config={'durationSecs': 8})
# before: durationSecs rode into parameters
# after: GenkitError INVALID_ARGUMENT naming durationSecs; nothing sent

Decisions

  • Strict all the way down: fix(py)!: an unknown config key raises before the model is called #6587 made the top level of Gemini config strict, but nested settings (thinking_config, safety_settings, speech_config, ...) and Veo still dropped or forwarded typos. Now every level raises with the dotted path, including tool options (google_search.exclude_domainz). Each nested class declares exactly its google-genai type's fields (SafetySetting.method, ImageConfig.output_mime_type, ...), and a test pins the sets so a new SDK field fails CI rather than users. extra= is how a field the class does not declare still reaches the API.
  • google_search is the tool switch: The old google_search_retrieval name pointed at a retired tool, and any non-None value attached search, so False turned it on. Now google_search=True attaches the tool, an options dict is validated against genai_types.GoogleSearch, and False or None attaches nothing. url_context and code_execution follow the same rule. The old name, and the JS spelling googleSearchRetrieval, fail with an error that names google_search rather than the generic unknown-key message.
  • Veo declares its SDK fields: Strict validation needs a full field list, so VeoConfig declares every GenerateVideosConfig field (e.g. generate_audio, number_of_videos) with camelCase aliases, pinned by a test. A key in config or in extra still raises the context.secrets error, not "put it in extra", so a tenant key never lands in the request body.
  • extra can't replace what Genkit builds: each family names its managed body fields. Gemini rejects contents, tools, ...; Veo rejects instances. A request's extra layers over the plugin's http_options.extra_body instead of replacing it.

Breaking changes

  • Nested Gemini config keys raise: a typo inside thinking_config, safety_settings, function_calling_config, speech_config, file_search, or image_config raises INVALID_ARGUMENT naming the path; move undeclared fields to extra under their REST name.
  • google_search_retrieval is removed: it fails INVALID_ARGUMENT with google_search_retrieval was renamed to google_search; use google_search / googleSearch.
  • google_search, url_context, code_execution take True or an options dict: False attaches nothing, and the options dict is validated against the SDK tool type. Before, any non-None google_search attached the tool, and code_execution={} attached nothing.
  • Unknown Veo config keys raise: put undeclared fields in extra={'parameters': {...}}.
  • Veo extra merges at its wire path: it used to land as a literal parameters.extra field. extra={'instances': ...} raises.
  • Dev UI config forms are closed: the JSON schema for these classes says additionalProperties: false.

API changes

  • GeminiConfig.google_search: bool | genai_types.GoogleSearch | None, alias googleSearch; replaces google_search_retrieval. url_context and code_execution are typed the same way with UrlContext / ToolCodeExecution.
  • VeoConfig declares SDK fields: number_of_videos, generate_audio, fps, output_gcs_uri, pubsub_topic, compression_quality, resize_mode, labels, last_frame, reference_images, mask, webhook_config, each with a camelCase alias.
  • VeoConfig.extra: dict[str, Any] | None, merged into the request body.

Cross-SDK

  • Strict config plus extra matches Go: Go uses SDK types with additionalProperties: false. JS schemas are passthrough, so unknown keys go to the provider body.
  • google_search matches JS Google AI's googleSearch. JS Vertex still only knows googleSearchRetrieval, so the old name fails with a targeted error naming google_search.
  • Veo fields cover JS's set, including Vertex-only generateAudio, compressionQuality, resizeMode, and location.

@github-actions github-actions Bot added docs Improvements or additions to documentation python Python fix labels Oct 6, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the configuration schemas for Gemini, Veo, and Lyria models to forbid undeclared configuration keys by setting extra='forbid' and marking additionalProperties as False in their JSON schemas. It also renames google_search_retrieval to google_search, explicitly declares supported fields on VeoConfig, and updates the test suite to verify that validation errors are raised on construction for unknown keys. There are no review comments, so I have no feedback to provide.

@huangjeff5
huangjeff5 force-pushed the fix/py-gemini-config-strict branch from e6b08a0 to 970750b Compare October 6, 2026 10:02
@huangjeff5 huangjeff5 changed the title fix(py/google-genai)!: Gemini and Veo config reject unknown keys; per-request key from context.secrets fix(py/google-genai)!: nested Gemini, Veo, and Lyria config reject unknown keys; google_search replaces google_search_retrieval Oct 6, 2026
@huangjeff5
huangjeff5 force-pushed the fix/py-gemini-config-strict branch from 970750b to f184e6f Compare October 6, 2026 10:12
@huangjeff5 huangjeff5 changed the title fix(py/google-genai)!: nested Gemini, Veo, and Lyria config reject unknown keys; google_search replaces google_search_retrieval fix(py/google-genai)!: strict nested Gemini, Veo, and Lyria config; google_search replaces google_search_retrieval Oct 6, 2026
…oogle_search replaces google_search_retrieval
@huangjeff5
huangjeff5 force-pushed the fix/py-gemini-config-strict branch from f184e6f to bdcaa36 Compare October 6, 2026 10:19
@huangjeff5
huangjeff5 requested a review from apascal07 October 6, 2026 22:13
@huangjeff5
huangjeff5 marked this pull request as ready for review October 6, 2026 22:14
@huangjeff5
huangjeff5 changed the base branch from fix/py-config-unknown-key-raises-main to fix/py-model-config-any-model October 7, 2026 04:56
@huangjeff5
huangjeff5 added this pull request to stack #6624 October 7, 2026 04:57
…Veo extra guards instances

- Each strict nested Gemini class declares exactly the fields of the
  google-genai type it is sent as (SafetySetting.method, ImageConfig
  output/person/prominent fields, FunctionCallingConfig
  .stream_function_call_arguments, VoiceConfig.replicated_voice_config).
  A test pins the field sets, so a new SDK field fails CI, not users.
- code_execution / google_search / url_context dicts validate against
  the SDK tool type: a bad key raises INVALID_ARGUMENT with its dotted
  path instead of FAILED 'internal error'. False attaches no tool.
- attach_config_extra takes the family's managed body fields; Veo
  rejects extra={'instances': ...} and keeps the plugin's extra_body.
- Drop Veo's unreachable leftovers branch and api_key re-checks.
- Leave the unused _lyria.LyriaConfig untouched; Interactions Lyria
  strictness lands in #6646.
@huangjeff5 huangjeff5 changed the title fix(py/google-genai)!: strict nested Gemini, Veo, and Lyria config; google_search replaces google_search_retrieval fix(py/google-genai)!: strict nested Gemini and Veo config; google_search replaces google_search_retrieval Oct 7, 2026
…nfig

- Rename ThinkingConfigSchema, FileSearchConfigSchema, ImageConfigSchema, VoiceConfigSchema, SpeakerVoiceConfigSchema, MultiSpeakerVoiceConfigSchema, and SpeechConfigSchema to *Config.
- Retain backwards-compatibility aliases in _gemini.py.
- Update tests and Dev UI schema $defs lookup.
…nto fix/py-gemini-config-strict

# Conflicts:
#	py/packages/genkit-google-genai/tests/models/googlegenai_gemini_test.py
#	py/packages/genkit-google-genai/tests/veo_test.py
@huangjeff5
huangjeff5 merged commit f8aca98 into main Oct 8, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation fix python Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants