Gemini on Vertex UNEXPECTED_TOOL_CALL error [AI SDK 5]
Description
I am getting this error on every tool call using gemini models via the google-vertex provider, for example:
{
content: {
},
finishReason: "UNEXPECTED_TOOL_CALL",
finishMessage: "Unexpected tool call: print(default_handler.save_plan(steps=[default_handler.Action(thought='The user is asking to search the internet for the latest news on Vercel. The `internetSearch` tool is the most appropriate tool for this purpose.', step='1. Use the `internetSearch` tool to search for \\'latest news on Vercel\\'.')]))",
}
The same tool call succeeds if I call via google vertex's SDK in node.
The definition is in the tools.functionDeclarations in the request param vercel sends:
{
"name": "savePlan",
"description": "Used to save a plan in a structured format",
"parameters": {
"required": ["plan"],
"type": "object",
"properties": {
"plan": {
"description": "A plan is a set of steps to follow in order to achieve a goal",
"required": ["steps"],
"type": "object",
"properties": {
"steps": {
"description": "List of steps to follow",
"type": "array",
"items": {
"description": "The step to follow",
"required": ["step", "id"],
"type": "object",
"properties": {
"step": {
"description": "The step to follow. A step is just an instruction that will be displayed to the user and also used by the LLM to help generate a response",
"type": "string"
},
"id": {
"description": "The ID of the step. The first step should have id S1, the second S2, etc. These should not be exposed to the user",
"type": "string"
}
}
}
}
}
}
}
}
}
I can't tell any obvious cause for this as this seem like a valid json schema, and is in fact similar to what I am sending via the vertex sdk directly as shown below(which works!):
{
name: "savePlan",
description: "Used to save a plan in a structured format",
parameters: {
type: "object",
additionalProperties: false,
properties: {
plan: {
type: "object",
additionalProperties: false,
properties: {
steps: {
type: "array",
items: {
type: "object",
additionalProperties: false,
properties: {
step: {
type: "string",
description: "The step to follow. A step is just an instruction that will be displayed to the user and also used by the LLM to help generate a response",
},
id: {
type: "string",
description: "The ID of the step. The first step should have id S1, the second S2, etc. These should not be exposed to the user",
},
},
required: [
"step",
"id",
],
description: "The step to follow",
},
description: "List of steps to follow",
},
},
required: [
"steps",
],
description: "A plan is a set of steps to follow in order to achieve a goal",
},
},
required: [
"plan",
],
},
}
Any idea what's going on here? The only difference is in the additionalProperties field. I am converting the parameters for vercel via jsonSchema method from ai
Thanks!
AI SDK Version
No response
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
can you by chance share a minimal code example using the AI SDK producing the error, and ideally also the vertex sdk where it works correctly?
I am so very sorry - it's actually a user error. Managed to get it to work. Thanks!
No worries, thanks for letting us know. Glad you got it working!
@RuoniWang-at what was the user error? Im also facing same issue while migrating
@RuoniWang-at I'm having the same issue, and it's a problem with my write plan tool as well. What was your issue?
I found what the problem was. Maybe it will be useful for someone
I had a reminder (as a user model message) to call the create_plan tool, but in that iteration create_plan was not in activeTools, which caused UNEXPECTED_TOOL_CALL.
The biggest problem for me was that it was failing silently without any exception. The finishReason was unknown, and I needed to debug the raw chunk to understand the problem.
I'm on @ai-sdk/[email protected] and [email protected] versions
Identify issue type
Identified as None
Confidence: High
Rationale
The reported behavior was ultimately attributed to application configuration rather than a confirmed AI SDK failure, making this primarily a resolved support/debugging issue.
Evidence
- The reporter explicitly clarified that the problem was user error and that they got it working.
- A later commenter traced the same error to prompting the model to call
create_planwhile that tool was absent fromactiveTools. - No reproducible AI SDK defect or requested product/documentation change was established.