Bug: Vertex AI strips tool parameters schema to empty properties
Bug Report: Vertex AI function calling parameters schema stripped to empty properties
Description
When using tool() with custom parameters (either via jsonSchema() or dynamically-generated Zod schemas) with the Google Vertex AI provider, the tool parameters schema is incorrectly serialized. All property definitions are stripped out, leaving only an empty properties: {} object in the request sent to Vertex AI.
This causes all custom tools to fail with the error:
Unable to submit request because `<tool_name>` functionDeclaration parameters schema should be of type OBJECT
Environment
-
AI SDK Version:
[email protected](latest) -
Provider:
@ai-sdk/[email protected] - Runtime: Bun (also tested in Node.js)
-
Model:
gemini-2.0-flash-exp
Reproduction
Minimal Test Case
import { tool, streamText, jsonSchema } from 'ai';
import { vertex } from '@ai-sdk/google-vertex';
// Define a simple tool with parameters
const testTool = tool({
description: 'Update a workflow step',
parameters: jsonSchema({
type: 'object',
properties: {
step_id: {
type: 'string',
description: 'Step ID',
},
new_name: {
type: 'string',
description: 'New step name',
},
},
required: ['step_id', 'new_name'],
}, { validate: false }),
execute: async (params) => {
return { success: true };
},
});
// Try to use the tool
const model = vertex('gemini-2.0-flash-exp');
const result = await streamText({
model,
messages: [{ role: 'user', content: 'Test' }],
tools: { testTool },
});
// This fails with:
// Unable to submit request because `testTool` functionDeclaration
// parameters schema should be of type OBJECT
Also Fails with Zod
The same issue occurs when using Zod schemas:
import { z } from 'zod';
const testTool = tool({
description: 'Update a workflow step',
parameters: z.object({
step_id: z.string().describe('Step ID'),
new_name: z.string().describe('New step name'),
}),
execute: async (params) => {
return { success: true };
},
});
// Same error occurs
Expected Behavior
The request body sent to Vertex AI should contain the complete schema:
{
"functionDeclarations": [
{
"name": "testTool",
"description": "Update a workflow step",
"parameters": {
"type": "OBJECT",
"properties": {
"step_id": {
"type": "STRING",
"description": "Step ID"
},
"new_name": {
"type": "STRING",
"description": "New step name"
}
},
"required": ["step_id", "new_name"]
}
}
]
}
Actual Behavior
The request body sent to Vertex AI has empty properties:
{
"functionDeclarations": [
{
"name": "testTool",
"description": "Update a workflow step",
"parameters": {
"properties": {}
}
}
]
}
The type, required, and all property definitions are missing.
Evidence
I captured the actual request body from the error object:
for await (const chunk of result.fullStream) {
if (chunk.type === 'error') {
const error = chunk.error;
console.log('Request body:',
JSON.stringify(error.requestBodyValues.tools, null, 2)
);
}
}
Output shows empty properties for all custom tools.
Working Comparison
MCP tools created via experimental_createMCPClient().tools() work correctly with the same Vertex AI provider, suggesting the issue is specific to the schema serialization path used by tool().
Root Cause
The issue appears to be in how the Vertex AI provider serializes tool schemas. The schema is correctly constructed in memory (verified via logging), but gets stripped during serialization to the Vertex AI API format.
This may be related to issue #6572 which mentions "parameters.properties field missing in request body when using Vertex AI".
Impact
This bug makes it impossible to use custom tools with the Vertex AI provider unless they have no parameters. Only MCP-provided tools work correctly.
Workaround
Currently, the only workaround is to use experimental_createMCPClient() for all tools, which is not practical for custom application-specific tools.
Additional Context
- The schema cleaning/conversion logic works correctly (tested extensively)
- Both
jsonSchema()and Zod approaches fail identically - The error occurs during the HTTP request to Vertex AI
- MCP tools using the same provider work fine
- Error response from Vertex AI:
INVALID_ARGUMENTwith message about schema should be type OBJECT
Request
Please fix the schema serialization in the Vertex AI provider to preserve all schema properties when building function declarations for the Vertex AI API.
Update: Confirmed this bug exists in the latest versions:
-
[email protected](not 4.1.0 as initially stated) -
@ai-sdk/[email protected]
The issue persists in v5 of the AI SDK.
I've identified and fixed the bug!
Root cause: The Google provider was not calling asSchema().jsonSchema to extract the JSON Schema from tool.inputSchema, which is a FlexibleSchema type. This resulted in passing a Schema object (with a jsonSchema getter) instead of a plain JSONSchema7 object.
Pull request: #9762
The fix properly extracts the JSON schema using await asSchema(tool.inputSchema).jsonSchema, matching the pattern used in other parts of the codebase.
Hey @gr2m, @nicoalbanese, @lgrammel , could you please take a look at the PR I submitted? Link: https://github.com/vercel/ai/pull/9763
@sujal12344 why did you submit the same pr as #9762 ?
@louis030195 the fix cannot work imo. was this done with ai or did you do it yourself?
@lgrammel i use my branch in my project and it solved my problem