Skip to content

fix!: remap finish_reason to tool_calls when response contains tool calls#3102

Merged
sjrl merged 1 commit intodeepset-ai:mainfrom
SyedShahmeerAli12:fix/google-genai-finish-reason-tool-calls
Apr 9, 2026
Merged

fix!: remap finish_reason to tool_calls when response contains tool calls#3102
sjrl merged 1 commit intodeepset-ai:mainfrom
SyedShahmeerAli12:fix/google-genai-finish-reason-tool-calls

Conversation

@SyedShahmeerAli12
Copy link
Copy Markdown
Contributor

Fixes #2143.

Google GenAI returns STOP as finish_reason for both normal completions and tool calls (it has no dedicated FUNCTION_CALL finish reason). This makes the response indistinguishable from a normal text completion, breaking any downstream code that branches on finish_reason.

Fix: after mapping the raw Google finish reason, if the mapped value is "stop" and the response contains tool calls, remap it to "tool_calls". Applied to both the non-streaming (_convert_google_genai_response_to_chatmessage) and streaming (_convert_google_chunk_to_streaming_chunk) paths.

@SyedShahmeerAli12 SyedShahmeerAli12 requested a review from a team as a code owner April 3, 2026 11:41
@SyedShahmeerAli12 SyedShahmeerAli12 requested review from sjrl and removed request for a team April 3, 2026 11:41
@github-actions github-actions bot added integration:google-genai type:documentation Improvements or additions to documentation labels Apr 3, 2026
@SyedShahmeerAli12 SyedShahmeerAli12 force-pushed the fix/google-genai-finish-reason-tool-calls branch from 447ec33 to 184a49e Compare April 3, 2026 11:44
@SyedShahmeerAli12
Copy link
Copy Markdown
Contributor Author

SyedShahmeerAli12 commented Apr 3, 2026

@sjrl .. Google GenAI has no dedicated FUNCTION_CALL finish reason ..... it returns STOP for both normal
completions and tool calls. This remaps it to tool_calls when tool calls are present, making
it consistent with other providers in Haystack.

@sjrl sjrl changed the title fix(google-genai): remap finish_reason to tool_calls when response contains tool calls fix!: remap finish_reason to tool_calls when response contains tool calls Apr 9, 2026
Copy link
Copy Markdown
Contributor

@sjrl sjrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sjrl sjrl merged commit 2cea62a into deepset-ai:main Apr 9, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:google-genai type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google GenAI: use finish_reason.tool_calls when the model produces a tool call?

2 participants