Skip to content

feat(ai): add new 'InvalidToolCall' part#14337

Draft
aayush-kapoor wants to merge 3 commits intomainfrom
aayush/invalid-tool-call
Draft

feat(ai): add new 'InvalidToolCall' part#14337
aayush-kapoor wants to merge 3 commits intomainfrom
aayush/invalid-tool-call

Conversation

@aayush-kapoor
Copy link
Copy Markdown
Collaborator

Background

there was a TODO comment talking about cleaning up the way we pass invalid tool calls (when incorrect json args are returned by the model)

previously, invalid tool calls were emitted as dynamic tool calls (even if the tool wasn't dynamic) and then a dummy tool-error output was passed in place of invalid tool calls so the model would get a matching tool result in the next step.

Summary

  • new tool call type InvalidToolCall
  • now to-response-messages.ts detects InvalidToolCall content parts and auto-generates error tool-results for the model, so generateText and streamText don't need to manufacture fake outputs
  • InvalidToolUIPart is its own UI part type with type: 'invalid-tool' and state: 'error', so the UI can render invalid tool calls distinctly from real execution errors or dynamic tools.

Manual Verification

will create an example

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 (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

@aayush-kapoor aayush-kapoor marked this pull request as draft April 10, 2026 21:48
@tigent tigent bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/ui anything UI related feature New feature or request labels Apr 10, 2026
// insert error tool outputs for invalid tool calls:
// TODO AI SDK 6: invalid inputs should not require output parts
const invalidToolCalls = stepToolCalls.filter(
toolCall => toolCall.invalid && toolCall.dynamic,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multi-step tool call loop terminates prematurely when invalid tool calls are present because clientToolCalls includes them but clientToolOutputs doesn't, causing the count comparison clientToolOutputs.length === clientToolCalls.length to be false.

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/ui anything UI related feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant