Gemini 2.5 Pro ending the turn when it tries calling a tool

Hi everyone,

I am running into an issue with the Gemini 2.5 Pro model. I have a tool named “code” which can be used by the model to run code in a sandbox. It seems like Gemini 2.5 Pro just ends the turn when it tries to call the tool. No errors appear - the stream just stops. I am using Vercel AI SDK.

It ends the turn without any errors and without calling the code tool:

Some interesting findings:

  1. Other tools like my ‘command’ tool consistently work for this model

  2. When the code tool is successfully called by a different model (like Claude 3.5 Sonnet) and I switch to Gemini 2.5 Pro, the model is suddenly able to consistently call the ‘code’ tool

  3. When I let Gemini 2.5 Pro call a different tool like my command tool and after that I let it call the code tool, it seems to work most of the time as well

I have no idea why this is happening as from the above findings Gemini 2.5 Pro is sometimes able to call the tool, so that should not be the issue. It can also call other tools without a problem. Other models are also able to call tools without problems.

Any ideas?

6 Likes

I am facing the same issue, at times when I execute the tool and return the result back gemini sends back an empty response and the conversation ends. Seems like this happens randomly.

3 Likes

I am also facing the same issue when using the example code from Function calling with the Gemini API

From the picture (repeated call to the API) with Gemini 2.5 Pro Preview it is possible to see that the model randomly return None values instead of FunctionCall objects.

3 Likes

I’m experiencing the same problem. I’m using Langchain’s ChatOpenAI to call the Gemini 2.5 API via OpenRouter, and sometimes the response doesn’t include any tool calls, even though it definitely should.

It seems like a case of hallucination to me, because when I enabled a retry mechanism, it occasionally returns the expected tool calls.

4 Likes

What is the mode that you are using? I have found that ANY works best in combination with a tellUser function made available to the model if they are user-facing.

Same issue with Vercel AI SDK, this happens so frequent and make this model almost not able to be used on real product.

4 Likes

Been having the same issue since 2.0 flash. How has this not been addressed by either Google, Vercel, or Langchain? What is going on here? “Modified by moderator”

2 Likes

Same issue on my side. With the ANY mode the tool is called way too often

1 Like

Relieved to see I am not the only one having issues. Did anyone found a solution yet? It seems like this is also happening with the the latest Gemini 2.5 Pro and gemini-2.5-flash-preview-05-20 model

I am still not sure if this is a model issue or a Vercel AI SDK issue. All other models do seem to call tools correctly except the Gemini models

it’s a bummer as this makes these models unusable for me