Gemini API grounding showing internal reasoning instead of final answer
I’m calling gemini-2.5-flash-preview-04-17 with grounding enabled. (tried it also with gemini-2.5-pro-exp-03-25 → same issue)
message is a simple user prompt, e.g.:
„how is the weather in London today?“
The response begins with Gemini’s internal reasoning / plan, e.g.:
„The user is asking about the weather in London today.
I need to find the current weather conditions and the forecast for today in London.„
1 Like
Hey @Sen_Yussn , I just checked the prompt you shared with both 2.5 models and got the expected response. Sharing the colab gist for reference.
Thanks
Hey @GUNAND_MAYANGLAMBAM , thanks for the answer.
You made me recheck my code.
I got the solution (btw the issue took place within my Swift Code):
Gemini’s generateContent API often returns two items in content.parts:
- a thought object – the model’s internal reasoning (“thought”: 1)
- the actual answer – plain text with no thought key
If you always grab the first element (parts.first) you’ll get the reasoning instead of the answer.
this is inside of “content”:
[“parts”: <__NSArrayI 0x11c1ff120>(
{
text = “The user is asking about the current weather in London. I need to use the search tool to find this information. I will search for "weather in London today".”;
thought = 1;
},
{
text = “The weather in London, United Kingdom today, Friday, May 2, 2025, is mostly cloudy. The temperature is around 24\U00b0C (76\U00b0F) and feels like 25\U00b0C (77\U00b0F). There is a low chance of rain, around 0%. The humidity is around 45%.\n\nThe forecast for the rest of the day includes sunny intervals changing to cloudy by lunchtime. The maximum daytime temperature is expected to be 26\U00b0C.”;
}
)
, “role”: model]
Filter out any part that contains “thought” and keep the first one that doesn’t.
swift:
// decode → [String: Any] as usual …
if let json = try JSONSerialization.jsonObject(with: data) as? [String: Any],
let candidates = json[“candidates”] as? [[String: Any]],
let content = candidates.first?[“content”] as? [String: Any],
let parts = content[“parts”] as? [[String: Any]],
// pick the first part without a “thought” key
let answerPart = parts.first(where: { $0[“thought”] == nil }),
let text = answerPart[“text”] as? String {
completion(text.trimmingCharacters(in: .whitespacesAndNewlines))
} else {
completion(nil)
}
Now text will hold only the final grounded answer, no chain-of-thought.
2 Likes