Skip to content

fix: default undefined tool-call input to empty object in convertToModelMessages#14361

Open
Yanhu007 wants to merge 1 commit intovercel:mainfrom
Yanhu007:fix/convert-to-model-messages-undefined-input
Open

fix: default undefined tool-call input to empty object in convertToModelMessages#14361
Yanhu007 wants to merge 1 commit intovercel:mainfrom
Yanhu007:fix/convert-to-model-messages-undefined-input

Conversation

@Yanhu007
Copy link
Copy Markdown

Summary

Fixes #14349

When a tool UI part has state: 'output-available' but no input field (e.g. a tool with no parameters, or input not persisted to DB), convertToModelMessages produces a tool-call part with input: undefined. The OpenAI provider then serializes this without arguments, causing:

Missing required parameter: 'input[N].arguments'

This breaks chat history replay permanently — once such a message is persisted, the conversation is stuck.

Fix

Default part.input to {} when undefined in the non-error path (line 209):

- : part.input,
+ : (part.input ?? {}),

The output-error path already had a fallback chain (part.input ?? rawInput ?? undefined); this adds the same safety to the normal path.

…delMessages

When a tool UI part has state 'output-available' but no input field
(e.g. a tool that takes no parameters, or input was not persisted),
convertToModelMessages produces a tool-call without input. The OpenAI
provider sends this without arguments, causing:

  Missing required parameter: 'input[N].arguments'

Default undefined input to {} so the provider always has a valid
arguments object to serialize.

Fixes vercel#14349
@tigent tigent bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label ai/ui anything UI related bug Something isn't working as documented provider/openai Issues related to the @ai-sdk/openai provider labels Apr 12, 2026
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 ai/ui anything UI related bug Something isn't working as documented provider/openai Issues related to the @ai-sdk/openai provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: convertToModelMessages omits input on tool-call parts when input is undefined, causing OpenAI "Missing required parameter: arguments" error

1 participant