ai icon indicating copy to clipboard operation
ai copied to clipboard

[Bug] Gemini 3 Pro/Flash Preview models output internal JSON as text when tools are provided

Open AmrAbuElyazid opened this issue 11 months ago • 23 comments

Description

Environment

  • @ai-sdk/google: 3.0.0
  • ai: 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

  1. Configure streamText with gemini-3-pro-preview model
  2. Provide any tool definitions
  3. Send a simple message like "hi"
  4. Model outputs JSON with thought and call fields 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-call when a tool is appropriate

Actual Behavior

The model outputs an internal JSON structure containing thought and call fields as plain text, regardless of:

  • thinkingConfig settings (tried all combinations)
  • toolChoice settings (auto, required, etc.)
  • structuredOutputs setting

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.0
  • ai: 6.0.1

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

AmrAbuElyazid avatar Dec 23 '25 05:12 AmrAbuElyazid

same here

snaiws avatar Dec 23 '25 05:12 snaiws

I temporarily solved it by guiding the model output to a fixed format and parsing it.

snaiws avatar Dec 23 '25 06:12 snaiws

same here too

xqinwl avatar Dec 23 '25 06:12 xqinwl

same here too. please check this asap!

latemonk avatar Dec 23 '25 08:12 latemonk

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

rossaaiofficial avatar Dec 23 '25 09:12 rossaaiofficial

Seeing this too :(

maccman avatar Dec 23 '25 11:12 maccman

same here. it started yesterday, suddenly.

marcius-llmus avatar Dec 23 '25 15:12 marcius-llmus

Thankfully found this thread as I was starting to go crazy trying to debug my app. Fingers crossed the un-F the api soon.

monobyte avatar Dec 23 '25 15:12 monobyte

Getting this same issue all of a sudden as well! Thought I was going crazy!

chanmathew avatar Dec 23 '25 17:12 chanmathew

thought i was going mad , please what is the solution ?

trimmytech avatar Dec 23 '25 17:12 trimmytech

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.

Image

olegsubbly avatar Dec 23 '25 18:12 olegsubbly

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.

Image

Yes, this happens with gemini-3-pro only for me, not flash.

longsman avatar Dec 23 '25 18:12 longsman

This infinite loop happens with me on tool call mode "REQUIRED". Is that the case with you?

AmrAbuElyazid avatar Dec 23 '25 18:12 AmrAbuElyazid

Sorry @longsman, yes it's a Gemini 3 pro. I should have mentioned this.

olegsubbly avatar Dec 23 '25 18:12 olegsubbly

@AmrAbuElyazid for me toolChoice = auto

olegsubbly avatar Dec 23 '25 19:12 olegsubbly

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.

@ai-sdk+google+3.0.1.patch

AmrAbuElyazid avatar Dec 23 '25 19:12 AmrAbuElyazid

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.

@ai-sdk+google+3.0.1.patch

I can confirm, it's working thanks @AmrAbuElyazid

olivermontes avatar Dec 23 '25 21:12 olivermontes

@AmrAbuElyazid it works for me as well. Thanks for digging deep.

olegsubbly avatar Dec 23 '25 21:12 olegsubbly

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.

@ai-sdk+google+3.0.1.patch

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":

snaiws avatar Dec 24 '25 06:12 snaiws

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

chanmathew avatar Dec 24 '25 16:12 chanmathew