Skip to content

feat(py/plugins/google-genai): finish_message for image models and effective config echo - #5859

Closed
cabljac wants to merge 7 commits into
jh-interactions-1-corefrom
jh-gemini-finish-message
Closed

cabljac wants to merge 7 commits into
jh-interactions-1-corefrom
jh-gemini-finish-message

Conversation

@cabljac

@cabljac cabljac commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Parallel slice of the #5806 split (based on #5854, independent of the Interactions chain): normalizes finish reasons (NO_IMAGE, IMAGE_OTHER), synthesizes finish_message when image models return no media so empty results are not silent successes, propagates finish_message onto candidates, echoes the normalized effective config on response.request, and drops the retired gemini-2.5-flash-image-preview registration.

Part of the stack splitting #5806; recombined it reproduces that PR byte-for-byte. Co-authored with @huangjeff5.

Breaking changes

  • gemini-2.5-flash-image-preview is no longer registered as a model (the GEMINI_2_5_FLASH_IMAGE_PREVIEW enum members remain, but the model name stops resolving). Use gemini-2.5-flash-image.

@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 removes the deprecated gemini-2.5-flash-image-preview model, introduces a mechanism to track and return the effective configuration (normalized to snake_case and including injected modalities) on the response's request copy, and improves handling of empty or blocked image generation responses by mapping new finish reasons (NO_IMAGE, IMAGE_OTHER) and providing descriptive finish messages. The reviewer suggests fully removing the unused GEMINI_2_5_FLASH_IMAGE_PREVIEW enum members and constants, which were left behind after removing the model from docstrings and registration.

Comment on lines 1042 to 1043
| `gemini-3-pro-image-preview` | Gemini 3 Pro Image Preview | Supported |
| `gemini-2.5-flash-image-preview` | Gemini 2.5 Flash Image Preview | Supported |
| `gemini-2.5-flash-image` | Gemini 2.5 Flash Image | Supported |

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.

medium

While the docstrings for VertexAIGeminiVersion and GoogleAIGeminiVersion have been updated to remove gemini-2.5-flash-image-preview, the actual enum members GEMINI_2_5_FLASH_IMAGE_PREVIEW are still defined in both enum classes, and the constant GEMINI_2_5_FLASH_IMAGE_PREVIEW remains defined in the file. To fully retire this model version, please remove these unused enum members and constants.

cabljac and others added 3 commits August 4, 2026 09:52
…l refs

Core plumbing extracted from #5806: FinishReason.ABORTED (schema + typing),
cancel-operation action kind and registry lookup, background operation
lifecycle updates in _background.py, generate_operation/check_operation
plumbing in _ai, and a config_schema parameter on model_ref.

Co-authored-by: Jeff Huang <huangjeff@google.com>
genkit-schema.json is generated from this zod enum by export:schemas;
adding aborted only to the generated JSON left CI's clean-working-tree
check failing once the build regenerated the schema.

Co-authored-by: Jeff Huang <huangjeff@google.com>
…nishReason

Regenerates go/ai/gen.go from genkit-schema.json (FinishReasonAborted) and
narrows the runtime-parameterized ModelRequest cast to type[BaseModel] to
match _override_input_schema's signature.

Co-authored-by: Jeff Huang <huangjeff@google.com>
@cabljac
cabljac force-pushed the jh-interactions-1-core branch from c0440db to 395d4d6 Compare August 4, 2026 08:52
cabljac and others added 4 commits August 4, 2026 10:43
mode='plain' replaced the field's core schema, so the config JSON schema
collapsed to an empty object, every traced dump warned, and mismatched
config instances passed validation. The field is now a left-to-right
union (dict | SerializeAsAny[ConfigT] | None) with a before-validator
coercing dicts into the bound schema; type checkers see ConfigT | None
with a shadow __init__ that accepts dicts. Validation also unnests the
wire output key so model_dump round-trips keep output config, which the
action input retry relies on when re-validating cross-schema configs.
Hardcoded googleai/vertexai suggestions misdirect users of other
plugins; build the hint from the registry's plugin names instead.
…fective config echo

Gemini slice extracted from #5806: normalizes finish reasons (NO_IMAGE,
IMAGE_OTHER), synthesizes finish_message when image models return no
media so empty results are not silent successes, propagates
finish_message onto candidates, echoes the normalized effective config
on response.request for debugging, and drops the retired
gemini-2.5-flash-image-preview registration.

Co-authored-by: Jeff Huang <huangjeff@google.com>
@cabljac
cabljac force-pushed the jh-gemini-finish-message branch from c9df52c to 9d401da Compare August 4, 2026 10:13
Comment on lines +239 to +248
if _content_has_media(content):
return None
if fr_name == 'IMAGE_SAFETY':
return 'Image blocked by safety filters.'
if fr_name == 'IMAGE_OTHER':
return 'Image generation stopped (IMAGE_OTHER). Try revising the prompt.'
if fr_name == 'NO_IMAGE':
return 'No image was returned. Try a clearer image prompt (for example, "draw a red circle on white").'
# Ambiguous prompts sometimes come back as STOP/OTHER/UNKNOWN with empty parts.
return 'No image was returned. Try a clearer image prompt (for example, "draw a red circle on white").'

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.

I think this guard is broader than the comment on the fallback intends. The comment says these come back with empty parts, but the check is not _content_has_media(content), which is also true of a non-empty text-only reply. GEMINI_IMAGE_SUPPORTS marks these models multiturn=True with TEXT, IMAGE modalities, so a text-only turn (the model asking a clarifying question, for example) is a normal outcome, and it now comes back carrying finish_message="No image was returned. Try a clearer image prompt...".

The new test_generate_echoes_normalized_effective_config actually constructs this exact case (image model, finish_reason='STOP', a single text part) but only asserts on response.request.config, so it passes without noticing. The empty-candidates path (prompt-level block) reaches the same fallback.

Could we gate the synthesized message on the reasons that actually mean no image was produced, and leave STOP with text content alone?

Comment on lines +221 to +222
'NO_IMAGE',
'IMAGE_OTHER',

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.

IMAGE_PROHIBITED_CONTENT and IMAGE_RECITATION are left unmapped, so they fall through to FinishReason.UNKNOWN and then pick up the generic "try a clearer image prompt" text, even though the non-image PROHIBITED_CONTENT and RECITATION both map to BLOCKED in the tuple above.

Both members exist as far back as the declared floor (google-genai>=1.63.0), so this is not a new-SDK concern. The practical effect is that a genuine content-policy block on an image model never surfaces as blocked, and the caller gets prompt-quality advice instead of a policy explanation.

Could we add both to the blocked tuple?

Comment on lines +1694 to +1697
elif is_tts_model(model_name):
effective['response_modalities'] = ['AUDIO']
elif is_image_model(model_name):
effective['response_modalities'] = ['TEXT', 'IMAGE']

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.

These two fallbacks look unreachable from the only caller. generate() already sets request_cfg.response_modalities unconditionally for TTS and image models before dispatching, so the first branch always wins by the time effective_config runs. test_generate_echoes_injected_modalities_when_config_omitted passes through that first branch too.

@huangjeff5
huangjeff5 force-pushed the jh-interactions-1-core branch from bb8be01 to fb3cbf1 Compare August 6, 2026 15:37
cabljac added a commit to genkit-ai/genkit-python that referenced this pull request Nov 13, 2026
…empty image replies

Ports the still-applicable part of genkit-ai/genkit#5859 (9d401da1d).

- The candidate's finish_message now reaches ModelResponse.finish_message
  in both generate and streaming, matching the JS plugin.
- Gemini native image models that return no media get a finish_message
  saying why, so an empty reply is not a silent success. Blocked reasons
  name the reason; MAX_TOKENS gets none, since finish_reason=length
  already says it.

Not ported: the core background-model changes (superseded upstream and
already here), the effective-config echo on response.request, and
dropping gemini-2.5-flash-image-preview (this repo keeps retired models
registered but hidden from autocomplete).

Co-authored-by: Jacob Cable <jacobcable94@gmail.com>
Upstream-Commit: genkit-ai/genkit@9d401da1d
Upstream-PR: genkit-ai/genkit#5859
@MichaelDoyle

Copy link
Copy Markdown
Contributor

Closing as obsolete: targets the temporary jh-interactions-1-core branch (Interactions already landed via #6240 / #6241), conflicts across 20 files, and edits pre-#6508 Python module paths (finish_message is already handled in _models/_gemini.py).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config docs Improvements or additions to documentation go js python Python root tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants