Skip to content

Map Gemini LANGUAGE and UNEXPECTED_TOOL_CALL finish reasons - #1100

Merged
Quim Muntal (qmuntal) merged 1 commit into
microsoft:mainfrom
PratikDhanaveFork:fix/gemini-finish-reason-parity
Sep 18, 2026
Merged

Quim Muntal (qmuntal) merged 1 commit into
microsoft:mainfrom
PratikDhanaveFork:fix/gemini-finish-reason-parity

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

Two Gemini finish reasons were unmapped in toFinishReason and fell through to the default, returning an empty FinishReason instead of their canonical framework values:

  • LANGUAGE (FinishReasonLanguage) — an unsupported-language content filter — should map to content_filter, alongside the other safety/recitation reasons.
  • UNEXPECTED_TOOL_CALL (FinishReasonUnexpectedToolCall) should map to tool_calls, alongside MALFORMED_FUNCTION_CALL.

The Python client maps both in _FINISH_REASON_MAP ("LANGUAGE": "content_filter", "UNEXPECTED_TOOL_CALL": "tool_calls"). Both constants exist in the pinned google.golang.org/genai SDK.

Change

  • Add genai.FinishReasonLanguage to the content_filter case and genai.FinishReasonUnexpectedToolCall to the tool_calls case.

Test

  • Extends the TestFinishReason_NonStreaming table with languagecontent_filter and unexpected_tool_calltool_calls. Both fail before the change (empty string), pass after.

toFinishReason dropped two Gemini finish reasons that the Python client
maps: LANGUAGE (an unsupported-language content filter) and
UNEXPECTED_TOOL_CALL. Both fell through to the default and returned an empty
string instead of their canonical framework values.

Map LANGUAGE to content_filter and UNEXPECTED_TOOL_CALL to tool_calls,
matching Python's _FINISH_REASON_MAP.
Copilot AI lite review requested due to automatic review settings September 18, 2026 12:18
@github-actions github-actions Bot added area:provider Changes files in the provider area area:provider/gemini Changes files in the provider / gemini area size:small At most 30 changed lines across at most 2 files labels Sep 18, 2026

Copilot AI 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.

🟢 Approval recommended

The mappings and regression tests are covered with no unresolved blocking issues.

Pull request overview

Maps Gemini LANGUAGE and UNEXPECTED_TOOL_CALL finish reasons to canonical framework values.

Changes:

  • Maps LANGUAGE to content_filter.
  • Maps UNEXPECTED_TOOL_CALL to tool_calls.
  • Adds regression tests.
File summaries
File Description
provider/geminiprovider/agent.go Adds both finish-reason mappings.
provider/geminiprovider/agent_test.go Tests both mappings.
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.

@qmuntal
Quim Muntal (qmuntal) added this pull request to the merge queue Sep 18, 2026
@github-actions github-actions Bot added kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure labels Sep 18, 2026
Merged via the queue into microsoft:main with commit 0e53b72 Sep 18, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider/gemini Changes files in the provider / gemini area area:provider Changes files in the provider area kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure size:small At most 30 changed lines across at most 2 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants