Repository navigation
Python: fix(google_ai): report more Gemini finish reasons as content_filter - #14632
Conversation
…filter finish_reason_from_google_ai_to_semantic_kernel mapped only SAFETY to CONTENT_FILTER, so responses Gemini stopped for RECITATION, BLOCKLIST, PROHIBITED_CONTENT, SPII or the image variants came back with no finish reason at all, which looks like an unfinished response. These now map to CONTENT_FILTER, as SAFETY already does.
There was a problem hiding this comment.
🟢 Approval recommended
The focused mapping change preserves existing behavior, includes corresponding regression coverage, and has no identified blocking issues.
No open issues 🎉
What changed in this PR
Expands Gemini finish-reason handling so content-blocked responses are reported as CONTENT_FILTER rather than None.
Changes:
- Maps six additional finish reasons to
CONTENT_FILTER. - Adds parameterized regression coverage for each added reason.
- Preserves other mappings and leaves the deprecated Vertex AI connector unchanged.
| File | Description |
|---|---|
| python/tests/unit/connectors/ai/google/google_ai/services/test_google_ai_utils.py | Tests all six added content-filter reasons. |
| python/semantic_kernel/connectors/ai/google/google_ai/services/utils.py | Groups content-filter reasons and checks membership. |
Review effort: Balanced
|
Eduard van Valkenburg (@eavanvalkenburg) thanks for the approval. This was dropped from the merge queue by the merge-group run 40323553321, where "Python Pre-Merge Integration Tests - Agents" failed on an empty JSON response from Azure ( |
Motivation and Context
finish_reason_from_google_ai_to_semantic_kernelonly mappedSAFETYtoFinishReason.CONTENT_FILTER. Gemini also ends a response forRECITATION,BLOCKLIST,PROHIBITED_CONTENTandSPII(and the image variants available across the supported google-genai range), and for those the message came back withfinish_reason=None, indistinguishable from an unrecognised value or an unfinished response.Description
SAFETY,RECITATION,BLOCKLIST,PROHIBITED_CONTENT,SPII,IMAGE_SAFETYandIMAGE_PROHIBITED_CONTENTmap toFinishReason.CONTENT_FILTER.STOPandMAX_TOKENSare unchanged; other reasons (OTHER,MALFORMED_FUNCTION_CALL, ...) still returnNone.mainand pass with the change.tests/unit/connectors/ai/googlepasses (158).vertex_aiconnector is left as is.Contribution Checklist
This change was made with Claude Code; the tests were run against
mainand the branch.