[Bug] Gemini 3 Pro/Flash Preview models output internal JSON as text when tools are provided
Description
Environment
@ai-sdk/google: 3.0.0ai: 6.0.1- Node.js: (latest)
Problem
When using Gemini 3 Pro Preview (gemini-3-pro-preview) or Gemini 3 Flash Preview (gemini-3-flash-preview) models with tool definitions, the model outputs its internal JSON format as plain text instead of making proper tool calls.
Example output when just saying "hi" with tools defined:
{ "thought": "The user has initiated the conversation with a greeting. I should respond professionally...", "call": null }
Steps to Reproduce
- Configure
streamTextwithgemini-3-pro-previewmodel - Provide any tool definitions
- Send a simple message like "hi"
- Model outputs JSON with
thoughtandcallfields as text instead of responding normally
Expected Behavior
The model should either:
- Respond with normal text when no tool call is needed
- Make a proper
tool-callwhen a tool is appropriate
Actual Behavior
The model outputs an internal JSON structure containing thought and call fields as plain text, regardless of:
thinkingConfigsettings (tried all combinations)toolChoicesettings (auto, required, etc.)structuredOutputssetting
Notes
- Gemini 2.5 Pro works correctly with the same tool definitions
- Removing tools entirely makes the model respond normally
- This appears to be a fundamental incompatibility between Gemini 3 Preview models and tool calling in the current SDK
AI SDK Version
@ai-sdk/google: 3.0.0ai: 6.0.1
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
same here
I temporarily solved it by guiding the model output to a fixed format and parsing it.
same here too
same here too. please check this asap!
That's not an AI-SDK problem; it's a Gemini 3 model/API problem.
Below is a forum discussion:
https://discuss.ai.google.dev/t/gemini-responds-with-structured-json-like-output-only-when-function-calling-is-enabled/112993
Seeing this too :(
same here. it started yesterday, suddenly.
Thankfully found this thread as I was starting to go crazy trying to debug my app. Fingers crossed the un-F the api soon.
Getting this same issue all of a sudden as well! Thought I was going crazy!
thought i was going mad , please what is the solution ?
The same is happening for me.
I do not know if it's related, but it's going in circles with finishing. Does this happen to anyone else or only me? Previously, it was working fine, but it just started happening now.
The same is happening for me.
I do not know if it's related, but it's going in circles with finishing. Does this happen to anyone else or only me? Previously, it was working fine, but it just started happening now.
![]()
Yes, this happens with gemini-3-pro only for me, not flash.
This infinite loop happens with me on tool call mode "REQUIRED". Is that the case with you?
Sorry @longsman, yes it's a Gemini 3 pro. I should have mentioned this.
@AmrAbuElyazid for me toolChoice = auto
Hi all, quick update I found a workaround in case anyone is blocked on Gemini 3 Pro/Flash Preview + tools.
In @ai-sdk/google, the "auto" path currently returns:
// node_modules/@ai-sdk/google/dist/index.mjs | Line 834 -> 839
case "auto":
return {
tools: [{ functionDeclarations }],
toolConfig: { functionCallingConfig: { mode: "AUTO" } },
toolWarnings
};
If you let Gemini-3 default its own AUTO mode instead, tool calling behaves correctly again.
This conditional change fixes it for me:
toolConfig: modelId.includes("gemini-3")
? void 0
: { functionCallingConfig: { mode: "AUTO" } },
I’m attaching a small .patch that applies cleanly on @ai-sdk/google 3.0.1 (released a couple of hours ago) in case anyone wants to try it immediately. Hope this helps.
Hi all, quick update I found a workaround in case anyone is blocked on Gemini 3 Pro/Flash Preview + tools.
In @ai-sdk/google, the "auto" path currently returns:
// node_modules/@ai-sdk/google/dist/index.mjs | Line 834 -> 839 case "auto": return { tools: [{ functionDeclarations }], toolConfig: { functionCallingConfig: { mode: "AUTO" } }, toolWarnings }; If you let Gemini-3 default its own AUTO mode instead, tool calling behaves correctly again.
This conditional change fixes it for me:
toolConfig: modelId.includes("gemini-3") ? void 0 : { functionCallingConfig: { mode: "AUTO" } }, I’m attaching a small .patch that applies cleanly on @ai-sdk/google 3.0.1 (released a couple of hours ago) in case anyone wants to try it immediately. Hope this helps.
I can confirm, it's working thanks @AmrAbuElyazid
@AmrAbuElyazid it works for me as well. Thanks for digging deep.
Hi all, quick update I found a workaround in case anyone is blocked on Gemini 3 Pro/Flash Preview + tools.
In @ai-sdk/google, the "auto" path currently returns:
// node_modules/@ai-sdk/google/dist/index.mjs | Line 834 -> 839 case "auto": return { tools: [{ functionDeclarations }], toolConfig: { functionCallingConfig: { mode: "AUTO" } }, toolWarnings }; If you let Gemini-3 default its own AUTO mode instead, tool calling behaves correctly again.
This conditional change fixes it for me:
toolConfig: modelId.includes("gemini-3") ? void 0 : { functionCallingConfig: { mode: "AUTO" } }, I’m attaching a small .patch that applies cleanly on @ai-sdk/google 3.0.1 (released a couple of hours ago) in case anyone wants to try it immediately. Hope this helps.
this works for me
diff --git a/node_modules/@ai-sdk/google/dist/index.js b/node_modules/@ai-sdk/google/dist/index.js
index 5302118..87f0b72 100644
--- a/node_modules/@ai-sdk/google/dist/index.js
+++ b/node_modules/@ai-sdk/google/dist/index.js
@@ -826,7 +826,7 @@ function prepareTools({
case "auto":
return {
tools: [{ functionDeclarations }],
- toolConfig: { functionCallingConfig: { mode: "AUTO" } },
+ toolConfig: modelId.includes("gemini-3") ? void 0 : { functionCallingConfig: { mode: "AUTO" } },
toolWarnings
};
case "none":
diff --git a/node_modules/@ai-sdk/google/dist/index.mjs b/node_modules/@ai-sdk/google/dist/index.mjs
index 4c60984..e3e16fd 100644
--- a/node_modules/@ai-sdk/google/dist/index.mjs
+++ b/node_modules/@ai-sdk/google/dist/index.mjs
@@ -834,7 +834,7 @@ function prepareTools({
case "auto":
return {
tools: [{ functionDeclarations }],
- toolConfig: { functionCallingConfig: { mode: "AUTO" } },
+ toolConfig: modelId.includes("gemini-3") ? void 0 : { functionCallingConfig: { mode: "AUTO" } },
toolWarnings
};
case "none":
Looks like Logan from Google and team have identified the root issue and is rolling back: https://discuss.ai.google.dev/t/gemini-responds-with-structured-json-like-output-only-when-function-calling-is-enabled/112993/48?u=mathewchan