`@ai-sdk/google{-vertex}`: ignores `strict:true` on tools
Description
In the AI SDK Google and Google Vertex providers, tool strictness is not reflected in Gemini function-calling mode.
From an end-user perspective, setting strict: true on tools should enable validated/strict function calling behavior, but today the provider sends ANY (or AUTO/NONE) only.
Minimal Reproduction
import { generateText, tool } from 'ai';
import { google } from '@ai-sdk/google';
import { z } from 'zod';
await generateText({
model: google('gemini-3-flash-preview'),
toolChoice: 'required',
tools: {
createMeeting: tool({
description: 'Create a meeting',
inputSchema: z.object({
title: z.string(),
startTime: z.string(),
attendees: z.array(z.string()),
}),
strict: true, // ignored
}),
},
prompt: 'Schedule a product review tomorrow with [email protected]',
});
Expected
When tool strictness is requested (strict: true), Gemini should use validated function calling mode (VALIDATED).
https://ai.google.dev/gemini-api/docs/function-calling#function_calling_modes
Actual
Google provider currently maps function calling config modes to AUTO | NONE | ANY only, so validated mode is not used.
Impact
- Less predictable schema-conformant tool arguments
- Extra app-side validation/retry logic
- Inconsistent strict behavior across providers
Request
Please add support in the Google/Gemini provider to use VALIDATED mode when strict tool behavior is requested (e.g. strict: true), and keep existing behavior for non-strict tools.
AI SDK Version
No response
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
I'd like to work on this.
Looking at packages/google/src/google-prepare-tools.ts, the toolConfig.functionCallingConfig.mode type is currently 'AUTO' | 'NONE' | 'ANY' — missing 'VALIDATED'.
One design question: Gemini's VALIDATED mode is a global functionCallingConfig setting, while strict in the AI SDK is per-tool. If some tools have strict: true and others don't, we need a policy:
- If any tool has
strict: true, useVALIDATEDmode — safest, matches the intent of requesting strict validation - Only use
VALIDATEDwhen all tools havestrict: true— more conservative
I'd lean toward option 1, since a user setting strict: true on any tool clearly wants schema validation enforced.
The implementation would:
- Add
'VALIDATED'to the mode union type - Check if any tool in the
toolsarray hasstrict: true - If so, set mode to
'VALIDATED'instead of the default for that toolChoice type - This applies to
auto,required, andtoolchoice types
Would appreciate guidance on the preferred approach before submitting a PR.
Personally, I agree with option 1: "If any tool has strict: true, use VALIDATED mode — safest, matches the intent of requesting strict validation".
@echoVic feel free to submit a PR with this approach and we'll take a look if it works
Looks good to me. @aayush-kapoor what do you think?
:rocket: Published in:
| Package | Version |
|---|---|
@ai-sdk/google |
4.0.0-beta.1 |
@ai-sdk/google-vertex |
5.0.0-beta.1 |
Identify issue type
Identified as Bug
Confidence: High
Rationale
This is a concrete failure of existing tool strictness behavior: the providers did not honor strict: true when configuring Gemini function calling.
Evidence
- Setting
strict: trueon a tool is ignored by the Google and Google Vertex providers. - The providers only mapped Gemini function-calling modes to
AUTO,NONE, orANY, omittingVALIDATED. - A maintainer invited a PR for mapping strict tools to
VALIDATED, and the change was later published in beta package versions.