Skip to content

fix(google): make codeExecutionResult.output optional in response schema#12361

Merged
dancer merged 2 commits intovercel:mainfrom
AhmadYasser1:fix/google-code-execution-result-optional-output
Feb 9, 2026
Merged

fix(google): make codeExecutionResult.output optional in response schema#12361
dancer merged 2 commits intovercel:mainfrom
AhmadYasser1:fix/google-code-execution-result-optional-output

Conversation

@AhmadYasser1
Copy link
Copy Markdown
Contributor

@AhmadYasser1 AhmadYasser1 commented Feb 9, 2026

Background

When using vertex.tools.codeExecution({}) with Gemini 3 Flash (gemini-3-flash-preview), generateText throws AI_APICallError: Invalid JSON response because the Zod response schema requires codeExecutionResult.output to be a string. However, Gemini 3 Flash omits the output field entirely when code execution produces no text output (e.g., only saves files via PIL without printing to stdout).

Summary

  • Made the output field .nullish() in the codeExecutionResult Zod schema within getContentSchema(), which is shared by both the response and chunk schemas
  • Default missing output to an empty string ('') in both doGenerate and doStream code paths to maintain a consistent string type downstream
  • Added regression tests for both doGenerate and doStream with a missing output field

Manual Verification

  • All 231 tests in @ai-sdk/google pass (10 test files)
  • Full typecheck passes (pnpm type-check:full)
  • Lint and prettier pass

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Closes #12217

Gemini 3 Flash omits the `output` field in `codeExecutionResult` when
code execution produces no text output (e.g., only saves files via PIL).
This caused `AI_APICallError: Invalid JSON response` because the Zod
schema required `output` to be a string.

Changes:
- Make `output` field `.nullish()` in the `codeExecutionResult` schema
  within `getContentSchema()` (affects both response and chunk schemas)
- Default missing `output` to empty string in both doGenerate and
  doStream code paths
- Add regression tests for both generateText and streamText with
  missing output field

Closes vercel#12217
@vercel-ai-sdk vercel-ai-sdk bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label provider/azure Issues related to the @ai-sdk/azure provider labels Feb 9, 2026
@dancer dancer merged commit ba98c56 into vercel:main Feb 9, 2026
18 checks passed
@AhmadYasser1 AhmadYasser1 deleted the fix/google-code-execution-result-optional-output branch February 9, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label provider/azure Issues related to the @ai-sdk/azure provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@ai-sdk/google: codeExecutionResult.output should be optional in response schema — Gemini 3 Flash omits it

2 participants