Skip to content

Fix Gemini media prompt sanitization#121

Merged
genz27 merged 1 commit intoTheSmallHanCat:mainfrom
zy6p:fix-gemini-media-prompt-sanitizer
Apr 14, 2026
Merged

Fix Gemini media prompt sanitization#121
genz27 merged 1 commit intoTheSmallHanCat:mainfrom
zy6p:fix-gemini-media-prompt-sanitizer

Conversation

@zy6p
Copy link
Copy Markdown
Contributor

@zy6p zy6p commented Apr 14, 2026

Summary

  • sanitize Gemini image/video prompts before forwarding them to Flow
  • ignore tool/function-calling scaffolding in systemInstruction for media models
  • strip <tools>...</tools> blocks and agent preamble lines from media prompts

Why

Gemini-compatible clients sometimes send agent/tool scaffolding such as:

  • You are a function calling AI model
  • <tools>...</tools> blocks
  • JSON schema for tool definitions

For text models that can be acceptable context, but for Flow media generation these lines are not valid prompt content. flow2api currently forwards them verbatim, which can make image generation fail with:

PUBLIC_ERROR_UNSAFE_GENERATION: Request contains an invalid argument.

This is reproducible even when the actual image prompt is valid. The failure is in the route normalization layer, not the Flow model mapping itself.

Verification

  • reproduced success for clean gemini-3.1-flash-image-square and gemini-3.1-flash-image-four-three prompts
  • reproduced failure when the same request included agent/tool scaffolding in the media prompt
  • after this patch, the normalized media prompt only keeps the actual image description and generation succeeds

@genz27 genz27 merged commit e072589 into TheSmallHanCat:main Apr 14, 2026
2 checks passed
@zy6p zy6p deleted the fix-gemini-media-prompt-sanitizer branch April 15, 2026 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants