-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Description
Summary
The native Gemini API now supports combining Google Search grounding with structured outputs in a single call (Gemini 3+), but @ai-sdk/google doesn't expose this capability yet.
Native Gemini API Support
From the official Gemini documentation:
"Gemini 3 lets you combine Structured Outputs with built-in tools, including Grounding with Google Search, URL Context, Code Execution, and File Search."
This is available for gemini-3-pro-preview and gemini-3-flash-preview models. Ultimately they are now used with latest.
Current Limitation in @ai-sdk/google
When using @ai-sdk/google, you cannot use Google Search grounding (useSearchGrounding: true) together with structured outputs. This forces a workaround with two separate API calls:
- Phase 1: Call with grounding enabled to search and gather information (no structured output)
- Phase 2: Call without grounding to extract structured JSON from the Phase 1 results
This adds latency, doubles API costs, and introduces complexity in matching grounding sources between phases.
Desired Behavior
Allow combining grounding with structured outputs in a single call, matching what the native Gemini API supports:
const result = await generateObject({
model: google("gemini-3-flash-preview", {
useSearchGrounding: true,
}),
schema: mySchema,
prompt: "Research this topic and return structured data",
});
// result.object contains structured data
// result.experimental_providerMetadata?.google?.groundingMetadata contains sourcesReferences
- Gemini structured output docs: https://ai.google.dev/gemini-api/docs/structured-output
- Gemini grounding docs: https://ai.google.dev/gemini-api/docs/grounding
AI SDK Version
- ai: 6.0.6
- @ai-sdk/google: 3.0.2
Code of Conduct
- I agree to follow this project's Code of Conduct