Beta 5 - Incomplete tool input part breaking the whole chat history
Description
When there is an invalid tool call in history, the convertToModelMessages fails to convert to model messages, breaking the whole experience and forcing the user to start a new chat session. It should probably just be ignored so the user can keep with their chat session.
After a tool has called with invalid input, the user cannot move forward in the same chat session as it throws this:
Chat Client Tools API error: Error [AI_MessageConversionError]: incomplete tool input is not supported: call_cFYQgCzSZOqMLrd0EAeNrIMY
at POST (src/app/api/chat-client-tools/route.ts:11:39)
9 | const result = streamText({
10 | model: openai('gpt-4o-mini'),
> 11 | messages: convertToModelMessages(messages),
| ^
12 | tools: {
13 | updateSlide,
14 | }, {
cause: undefined,
originalMessage: [Object]
}
POST /api/chat-client-tools 500 in 80ms
AI SDK Version
"@ai-sdk/openai": "2.0.0-beta.5", "@ai-sdk/react": "2.0.0-beta.7",
What behavior would you ideally want? omit partial or incomplete tool calls? or have an option to opt-in into omitting them?
Ideally, there would be an option to filter out those calls, or provide a util to filter those out.
I don't really get why incomplete tool calls are a problem (I am just starting with the library, it may be obvious for others) since I was just calling convertToModelMessages to get the model messages to provide context for the ai.
You can now use the ignoreIncompleteToolCalls option on convertToModelMessages.
However, be careful with using it, most of the time those errors point to underlying issues with the tool calls.
Incomplete tool calls are a problem because they will be rejected by LLM provider APIs.
@lgrammel we saw the same issue yesterday. In our case streamText finished while a tool call was still in an input-streaming state, for an unknown reason. We then persisted the incomplete data to our DB which triggered the error on the next round of the conversation, when it attempted to convert the persisted UI messages to model messages. Is there any recommended approach to detecting and debugging incomplete tool calls in the Beta?
Identify issue type
Identified as Feature
Confidence: High
Rationale
This requests an API capability to optionally omit incomplete tool calls. The existing rejection was explained as intentional, so the added opt-in filtering is an enhancement rather than a confirmed defect.
Evidence
convertToModelMessagesintentionally rejected incomplete tool calls because provider APIs will reject them.- The reporter requested an option or utility to filter incomplete calls rather than identifying a documented behavior that was violated.
- A maintainer added the new
ignoreIncompleteToolCallsoption to provide the requested opt-in behavior.