Map Gemini image-safety finish reasons to content_filter - #1006
Conversation
toFinishReason mapped the text content-policy reasons (SAFETY, RECITATION, BLOCKLIST, PROHIBITED_CONTENT, SPII) to content_filter but let the image-generation equivalents (IMAGE_SAFETY, IMAGE_PROHIBITED_CONTENT, IMAGE_RECITATION) fall through to the default empty string. A response blocked by image-safety policy therefore reported no finish reason instead of content_filter, an inconsistency within the same content-policy category. Map the image-safety reasons alongside their text counterparts.
There was a problem hiding this comment.
🟢 Approval recommended
The mapping change is straightforward, consistent with existing semantics, and is covered by an expanded unit test.
Pull request overview
This PR aligns the Gemini provider’s finish-reason mapping with the framework’s cross-provider content_filter contract by including the genai SDK’s image-safety finish reasons, preventing blocked image-generation responses from reporting an empty finish reason.
Changes:
- Map
IMAGE_SAFETY,IMAGE_PROHIBITED_CONTENT, andIMAGE_RECITATIONto the canonicalcontent_filterfinish reason. - Extend the existing non-streaming finish-reason table test to cover the new image-safety reasons.
File summaries
| File | Description |
|---|---|
| provider/geminiprovider/agent.go | Extends toFinishReason to treat image-safety finish reasons as content_filter. |
| provider/geminiprovider/agent_test.go | Adds table-driven test cases asserting content_filter for image-safety finish reasons. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Scope: user-visible behavior (unexported Changed Go contract: Upstream evidence reviewed: Result: aligned. The three image-safety reasons added in this PR match upstream Python's mapping to Note (non-blocking, out of scope for this PR): upstream Python also maps Warning Firewall blocked 2 domainsThe following domains were blocked by the firewall during workflow execution:
To allow these domains, add them to the network:
allowed:
- defaults
- "github.com"
- "raw.githubusercontent.com"See Network Configuration for more information.
|
Problem
toFinishReason(provider/geminiprovider/agent.go) maps the text content-policy finish reasons —SAFETY,RECITATION,BLOCKLIST,PROHIBITED_CONTENT,SPII— to the canonicalcontent_filter. But the genai SDK also defines image-generation equivalents in the same content-policy category:FinishReasonImageSafety(IMAGE_SAFETY),FinishReasonImageProhibitedContent(IMAGE_PROHIBITED_CONTENT), andFinishReasonImageRecitation(IMAGE_RECITATION). These fall through to thedefaultand return an empty string.So a response blocked by image-safety policy reports no finish reason, whereas the equivalent text-safety block reports
content_filter— an inconsistency within the same semantic category (and a gap vs. the cross-providercontent_filtercontract).Fix
Map the three image-safety reasons to
content_filteralongside their text counterparts.Test
Extends the existing
TestFinishReason_NonStreamingtable withIMAGE_SAFETY,IMAGE_PROHIBITED_CONTENT, andIMAGE_RECITATIONrows, each expectingcontent_filter. They fail before the fix (empty string), pass after.