-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Description
When using @ai-sdk/google-vertex with Gemini models and attempting manual tool execution, the SDK strips or rewrites the functionDeclarations.parameters schema, resulting in an invalid request being sent to Vertex AI.
Vertex AI requires functionDeclaration.parameters to be a valid JSON Schema with:
{
"type": "object",
"properties": { ... }
}However, even when valid schemas are provided, the SDK mutates the request and sends:
"parameters": {
"properties": {}
}This causes Vertex to return:
INVALID_ARGUMENT:
Unable to submit request because `readFile` functionDeclaration parameters schema should be of type OBJECT
Expected behavior
When manually supplying tool schemas for Gemini via Vertex AI:
- The SDK should preserve the provided JSON Schema
parameters.type = "object"should not be removed- Manual execution loops should be supported, or explicitly rejected at the SDK level
Actual behavior
parameters.typeis strippedrequiredandadditionalPropertiesare removed- The resulting request is rejected by Vertex
- This occurs even when tools are injected via
experimental_providerMetadata.google.tools
Minimal reproduction
import { generateText } from 'ai';
import { createVertex } from '@ai-sdk/google-vertex';
const vertex = createVertex({
project: 'my-project',
location: 'us-central1'
});
const tools = {
readFile: {
description: 'Read a file',
parameters: {
type: 'object',
properties: {
filePath: { type: 'string' }
},
required: ['filePath'],
additionalProperties: false
}
}
};
await generateText({
model: vertex('gemini-2.5-pro'),
system: 'Use tools when needed',
messages: [{ role: 'user', content: 'Read package.json' }],
toolChoice: 'auto',
experimental_providerMetadata: {
google: {
functionCallingConfig: { mode: 'ANY' },
tools: [{
functionDeclarations: Object.entries(tools).map(([name, t]) => ({
name,
description: t.description,
parameters: t.parameters
}))
}]
}
}
});Resulting error
INVALID_ARGUMENT:
Unable to submit request because `readFile` functionDeclaration parameters schema should be of type OBJECT
Notes
-
This issue does not occur with:
- Claude
- OpenAI
-
Gemini auto tool execution works, but manual execution loops are not possible
-
The SDK appears to normalize or re-serialize tools internally, overriding user-supplied schemas
-
Google’s own documentation requires
parameters.type = "object"
Suggested resolution
One of the following:
- Preserve user-supplied
functionDeclarationsverbatim when provided viaexperimental_providerMetadata - Allow a
rawTools/passthroughToolsoption for Gemini - Explicitly document that manual tool execution is not supported for Gemini and prevent this configuration
Environment
@ai-sdk/google-vertex: latestai: latest- Node.js: 22.x
- Model:
gemini-2.5-pro - Platform: AWS Lambda + Vertex AI
AI SDK Version
No response
Code of Conduct
- I agree to follow this project's Code of Conduct