[v5.0] reproduction: AIInvalidPromptError "messages must be a ModelMessage" caused by - #20283
Closed
ai-sdk-factory[bot] wants to merge 1 commit into
Closed
[v5.0] reproduction: AIInvalidPromptError "messages must be a ModelMessage" caused by#20283ai-sdk-factory[bot] wants to merge 1 commit into
ai-sdk-factory[bot] wants to merge 1 commit into
Conversation
Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com>
aayush-kapoor
left a comment
Collaborator
There was a problem hiding this comment.
closed via #20285
aayush-kapoor
added a commit
that referenced
this pull request
Sep 3, 2026
…ng undefined object properties (#20285) ## Background Manually reusing generated tool-result messages caused streamText and generateText continuations to reject valid outputs containing nested undefined object properties. ## Root Cause The recursive JSON value schema required every object property to be a JSONValue and rejected retained undefined values. The reproduction confirmed JSON serialization removed those properties and made continuation succeed. ## Summary Updated the internal JSON validator to permit undefined object properties, removed reproduction-only artifacts, and added an ai patch changeset. ## Testing Added a standardizePrompt regression test covering nested undefined properties in JSON tool-result arrays. ## End-to-end Validation - `pnpm -C examples/ai-functions exec tsx src/reproduction/issue-10893-undefined-tool-result-array.ts` via immutable replay exited successfully without the original bug signal. ## Related Issues Fixes #10893 Closes #20283 --------- Co-authored-by: ai-sdk-factory <308175966+ai-sdk-factory@users.noreply.github.com> Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com> Co-authored-by: wladimiiir <3164600+wladimiiir@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
AI_InvalidPromptError ("messages must be a ModelMessage[]") caused by undefined properties in tool-result arrays
Reproduction
release-v5.0withai5.0.251, manually reusing tool-response messages caused bothstreamTextandgenerateTextto reject the expected continuation withAI_InvalidPromptErrorcaused byAI_TypeValidationError.startedAtandcompletedAtas own properties withundefinedvalues;packages/ai/src/types/json-value.tsrejects those values, andpackages/ai/src/prompt/standardize-prompt.tsreports the misleadingModelMessage[]error.undefinedvalues—not heterogeneous arrays with missing keys—are the actual failure condition.nullsucceeded, and automatic multi-step execution usingstopWhen: stepCountIs(2)also succeeded.examples/ai-functions/src/reproduction/issue-10893-undefined-tool-result-array.ts, supported byexamples/ai-functions/package.json,examples/ai-functions/tsconfig.json, andpnpm-lock.yaml; it expects manual continuation to succeed but observes both APIs rejecting it.Related Issues
Reproduces #10893