Skip to content

Vertex Gemini function calling breaks when using manual tool execution (parameters schema stripped) #12183

@arulpr

Description

@arulpr

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.type is stripped
  • required and additionalProperties are 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:

  1. Preserve user-supplied functionDeclarations verbatim when provided via experimental_providerMetadata
  2. Allow a rawTools / passthroughTools option for Gemini
  3. Explicitly document that manual tool execution is not supported for Gemini and prevent this configuration

Environment

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions