Skip to content

AI SDK v6: tool().parameters not read by prepareToolsAndToolChoice (uses inputSchema which is undefined) #13460

Description

@LucasCzechia

Root Cause Found

tool() sets the schema on .parameters, but prepareToolsAndToolChoice and doParseToolCall read .inputSchema — which is undefined. This causes all tool schemas to fall through to the empty default {"properties":{},"additionalProperties":false}.

One-line fix in two locations in ai/dist/index.mjs:

- inputSchema: await asSchema(tool2.inputSchema).jsonSchema,
+ inputSchema: await asSchema(tool2.inputSchema ?? tool2.parameters).jsonSchema,
- const schema = asSchema3(tool2.inputSchema);
+ const schema = asSchema3(tool2.inputSchema ?? tool2.parameters);

How We Found It

const { tool } = require('ai');
const z = require('zod');
const t = tool({ description: 'test', parameters: z.object({ q: z.string() }), execute: async () => {} });

console.log(Object.keys(t));       // ['description', 'parameters', 'execute']
console.log(t.inputSchema);        // undefined
console.log(typeof t.parameters);  // object (zod schema)

tool() stores the zod schema on parameters. But prepareToolsAndToolChoice (line 1779) reads tool2.inputSchema which doesn't exist → asSchema(undefined) → returns the empty fallback {"properties":{},"additionalProperties":false}.

Similarly, doParseToolCall (line 3714) uses asSchema3(tool2.inputSchema) for validation → empty schema → validation against empty schema either fails or produces wrong results.

Impact

This breaks ALL tool calling for ALL providers when using tool() with Zod schemas in AI SDK v6. The model receives no parameter information, so:

  1. It guesses parameter names (sometimes query, sometimes q, sometimes {})
  2. Even when the model guesses correctly, doParseToolCall validates against the empty schema and may reject valid inputs

Verification

With the patch applied:

  • API receives correct tool schema with all properties
  • Model returns correct arguments 100% of the time
  • parseToolCall validates and passes correctly
  • 8/10 → limited only by model non-determinism, not SDK bugs

Without the patch: 0/10 — every tool call gets empty schema, model guesses, SDK rejects.

Environment

  • ai: 6.0.116
  • zod: 4.3.6
  • Tested with: Cloudflare Workers AI, @ai-sdk/openai-compatible
  • Both streamText and generateText affected

Previous Report (Updated)

The original report described two separate bugs. After investigation, both symptoms trace to this single root cause:

  • "Empty schema sent to API" → tool2.inputSchema is undefined, fallback produces {}
  • "SDK drops valid tool arguments" → doParseToolCall validates against empty schema, marks calls as invalid or produces wrong parsed values

The streaming-specific arguments: "{}" from Cloudflare was a red herring — it only happened because the empty schema gave the model no parameter guidance. With the correct schema, Cloudflare's streaming endpoint also returns correct arguments.

Related

This likely supersedes #12020 ("AI SDK v6 + Zod: Tool input_schema is empty when using Anthropic") — same root cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai/corecore functions like generateText, streamText, etc. Provider utils, and provider spec.bugSomething isn't working as documentedreproduction providedtask-identify-issue-type-done

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions