Repository navigation
feat(py)!: config pipeline: definition defaults, one merge, None is a value - #6712
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request unifies the configuration pipeline for models, embedders, and evaluators in Genkit, introducing generic EmbedRequest[Cfg] and EvalRequest[Cfg] types to support typed options. It consolidates config validation, layering, and default injection, and updates plugins to use custom_options_schema to filter out null defaults for the Dev UI. Feedback on these changes highlights a performance concern regarding the repeated instantiation of TypeAdapter in config_defaults, suggesting caching or pre-computing these instances to avoid overhead in Pydantic v2.
huangjeff5
force-pushed
the
feat/py-config-pipeline
branch
from
October 9, 2026 09:59
4932cab to
0bc31e6
Compare
huangjeff5
changed the base branch from
fix/py-embed-eval-options-dict
to
feat/py-config-class
October 9, 2026 10:00
huangjeff5
force-pushed
the
feat/py-config-pipeline
branch
from
October 9, 2026 15:47
0bc31e6 to
a0b2f10
Compare
huangjeff5
added a commit
that referenced
this pull request
Oct 12, 2026
This was referenced Nov 2, 2026
huangjeff5
force-pushed
the
feat/py-config-pipeline
branch
from
November 2, 2026 04:53
9e498db to
f41c73e
Compare
huangjeff5
force-pushed
the
feat/py-config-pipeline
branch
2 times, most recently
from
November 2, 2026 12:23
f41c73e to
d687ec2
Compare
huangjeff5
force-pushed
the
feat/py-config-pipeline
branch
from
November 2, 2026 16:58
d687ec2 to
7289d1b
Compare
pavelgj
approved these changes
Nov 2, 2026
huangjeff5
force-pushed
the
feat/py-config-pipeline
branch
from
November 2, 2026 23:57
7289d1b to
2769d65
Compare
huangjeff5
force-pushed
the
feat/py-config-pipeline
branch
from
November 3, 2026 02:02
63e412a to
a77e900
Compare
… value Unify model and embedder config merging and validation at Action.run: - Layer schema defaults < ref.version < ref.config < call config via one shared pipeline in _core/_config_check.py. - Treat explicit None as a value through layering and validation rather than stripping it early. - Validate whole merged configs at the Action.run boundary and strip null defaults from published customOptions. - Align GoogleAI.embedding() and VertexAI.embedding() with EmbedderRef[EmbeddingConfig].
huangjeff5
force-pushed
the
feat/py-config-pipeline
branch
from
November 3, 2026 02:58
a77e900 to
27919e8
Compare
… key A prompt called with a model other than its own (compared by name, so 'gem' and ModelRef(name='gem') are the same model) drops a key from both the prompt's and the call's config when the call sets it to None, the target's config class doesn't declare it, and the prompt's config has it. A None for a key the prompt doesn't have still raises unknown config key. Everywhere else None stays a value; ai.generate() is unchanged.
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.
A model's or embedder's config class, set at definition, owns the defaults and the shape. Every entry point (
ai.generate,ai.embed, the Dev UI, the CLI) goes through one merge and one validation at the action boundary, and setting a field toNone(config={"temperature": None}) overrides lower layers instead of being stripped (config=Nonestill means unset).Evaluators aren't covered: #6947 removes them from 1.0 pending a redesign.
Why the input used to differ
Two separate causes:
generateandembedlayered ref and call config with separate code, and they drifted.embedletref.versionbeatref.config['version'], the reverse ofgenerate.generatestrippedNone,embedpassed it through.TableConfig. An untyped fn got the raw dict. The Dev UI and CLI callAction.rundirectly and skippedgenerate's merge entirely.The fix for (1) is one merge helper. The fix for (2) is moving defaults and validation into
Action.run, the one point every path goes through.The rules
ModelRequest[Cfg]/EmbedRequest[Cfg], fromconfig_schema=, or from both, which must then be the same class. With neither, there are no defaults and no validation.schema defaults < ref.version < ref.config < call config.Noneschema defaults count.maxOutputTokensandmax_output_tokensare one setting.Noneis a value. It overrides lower layers, then validation decides.config=Nonestill means "nothing set".Action.run, after middleware.extra='forbid', orNoneon a non-optional field.wrap_modelmiddleware can still supply it.generatereturns that as a failed turn (finish_reason == FAILED).embed, the Dev UI and the CLI raise.config_schemamust name the action's class, or, for models, the genericModelConfig. A ref never adds defaults or changes the shape, because the Dev UI never has a ref.Decisions
Nonedefaults at the boundary, so typed and untyped fns see the same values from every entry point. Built-in plugin configs default every field toNone, so their wire calls are unchanged.generateandembed.EmbedderRefmirrorsModelRef, and both paths resolve the action, check the call config against its class, and layer through one helper.Nonestops meaning "unset".Nonereaches validation on every path. Plugin paths that read raw dicts (OpenAI TTS/image/STT, Bedrock image, Ollama) dropNoneto keep plugin defaults, so their requests are unchanged.customOptionsdrop"default": null. Pydantic writes it on every optional field. WithNonenow a value, a form that pre-fills defaults would sendnullfor every untouched field. Model, background-model and embedder metadata strip only null defaults;inputSchemais unchanged. This matches what JS publishes.SDK parity
Nonematch JS; Go replaces wholesale. Layeringversion < ref.config < calland preserving explicitNonematch JS (js/ai/src/generate.ts,embedder.ts), whereas Go replacesconfigwholesale (go/ai/generate.go).config_schemafield defaults and runtimeINVALID_ARGUMENTvalidation are deliberate Python ergonomics (JS typesconfigasz.any()and runs Ajv withoutuseDefaults).Breaking
Nonedefaults, validated on every path, including the Dev UI and CLI.config['maxOutputTokens']becomesconfig['max_output_tokens'].config={'field': None}on a non-optional field raisesINVALID_ARGUMENTup front. PassingNoneto clear a prompt's or ref's value now fails validation on a non-optional field.prompt(model='other', config={'thinkingConfig': None})dropsthinkingConfigfrom both the prompt's and the call's config whenother's class doesn't declare it and the prompt's config has it. ANonefor a key the prompt doesn't have ('temprature') still raises unknown config key. Models compare by name, so'gem'andModelRef(name='gem')are the same model, not a hop.ai.generate()is unchanged.{'max_output_tokens': 100, 'maxOutputTokens': 200}) raise. Across layers, the higher layer wins.config_schemanames another class raisesINVALID_ARGUMENT.EmbedderRefis a frozen generic dataclass likeModelRef, somodel_validate/model_dumpare gone. Whenversionandconfig['version']are both set, the config value wins.config_schemanext to a typed annotation raises at define time.strict: unknown config key 'thinking'), notInvalid input for model 'strict'.config.get('k', default)can now seeNonewhere the key used to be absent.mime_type/auto_truncateraise on the Gemini Developer API embedder; multimodal embedding raises ontask_type/title.GoogleAI.embedding()/VertexAI.embedding()dropped theversion=kwarg and dict config (useEmbeddingConfig(version=...)).Also in this PR: Google GenAI embedders
GoogleAI.embedding()andVertexAI.embedding()returnEmbedderRef[EmbeddingConfig]and takeconfig: EmbeddingConfig | None = None, mirroringgemini(). Pass raw dicts toai.embed(config=...).EmbeddingConfiginheritsGenkitConfig(extra='forbid'), so unknown keys fail withINVALID_ARGUMENT. Embedder actions bindconfig_schema=EmbeddingConfigand keep backend-filteredcustomOptionsfor the Dev UI.Where to look
py/packages/genkit/src/genkit/_core/_config_check.py: shared config pipeline (layer_call_config,overlay_config,config_defaults,check_config_values,validate_whole_config).py/packages/genkit/src/genkit/_core/_action.py:Action.runboundary default injection and whole-config validation.py/packages/genkit/src/genkit/_ai/_model.pyandpy/packages/genkit/src/genkit/_ai/_aio.py:call_config_class,resolve_call_config, and_embedder_and_options.py/packages/genkit-google-genai/src/genkit_google_genai/_models/_embedder.py:EmbeddingConfig(GenkitConfig) andEmbedderRef[EmbeddingConfig].