Skip to content

fix(py): serialize ModelInfo with camelCase aliases for Dev UI capability compatibility - #5964

Merged
huangjeff5 merged 4 commits into
genkit-ai:mainfrom
huangjeff5:fix/py-model-info-serialization
Aug 6, 2026
Merged

huangjeff5 merged 4 commits into
genkit-ai:mainfrom
huangjeff5:fix/py-model-info-serialization

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

When defining custom models or background models in Python (define_model and define_background_model), dumping ModelInfo without parameters serialized snake_case names (e.g. system_role, long_running, content_type, config_schema) and included None values.

This PR passes by_alias=True and exclude_none=True to info.model_dump(...) in _model.py and _background.py so field names are properly formatted as camelCase JSON aliases matching JS schema expectations and None fields are omitted.

This fixes an issue with Genkit Python on Dev UI. When the Dev UI evaluates `metadata.model.supports?.systemRole in JavaScript, "system_role" is not recognized, returning undefined. The UI interprets this as false and hides capability controls (such as the System Prompt input card). All the model info metadata is broken in the same way.

(I noticed this bug while testing with Ollama. Gemini/Vertex models have some magic on Dev UI side that hides this wire format inconsistency.)

Checklist

  • Unit tests updated and passing
  • Preflight lint and license checks passing

Manual inspection in Dev UI

I tested before/after using an Ollama sample.

BEFORE: System prompt is missing.
Screenshot 2026-08-05 at 7 31 37 PM

AFTER: system prompt renders correctly.
Screenshot 2026-08-05 at 7 31 20 PM

@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 define_model and define_background_model to serialize ModelInfo using by_alias=True and exclude_none=True when calling model_dump(), and adds corresponding unit tests. The review feedback highlights an issue in define_background_model where unconditionally setting model_options['label'] = label overwrites any custom label provided in info, and suggests updating both the implementation and the tests to handle and verify this correctly.

@huangjeff5
huangjeff5 requested review from apascal07 and pavelgj August 6, 2026 00:35
@huangjeff5 huangjeff5 changed the title fix(py): use by_alias and exclude_none when dumping ModelInfo fix(py): serialize ModelInfo with camelCase aliases for Dev UI capability compatibility Aug 6, 2026
@huangjeff5

Copy link
Copy Markdown
Contributor Author

@gemini review

@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 model definition functions to serialize model info using aliases and exclude null values, and refactors label resolution in background models to follow a clear precedence order. A review comment correctly points out a bug where the original label variable is still referenced in a cancel action description, which could lead to an incorrect description if label is not explicitly provided.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@huangjeff5
huangjeff5 enabled auto-merge (squash) August 6, 2026 01:53
@huangjeff5
huangjeff5 merged commit 3425a6b into genkit-ai:main Aug 6, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants