Skip to content

[v5.0] reproduction: AIInvalidPromptError "messages must be a ModelMessage" caused by - #20283

Closed
ai-sdk-factory[bot] wants to merge 1 commit into
release-v5.0from
bug-reproduction-10893-20260903170017672015
Closed

[v5.0] reproduction: AIInvalidPromptError "messages must be a ModelMessage" caused by#20283
ai-sdk-factory[bot] wants to merge 1 commit into
release-v5.0from
bug-reproduction-10893-20260903170017672015

Conversation

@ai-sdk-factory

@ai-sdk-factory ai-sdk-factory Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Bug

AI_InvalidPromptError ("messages must be a ModelMessage[]") caused by undefined properties in tool-result arrays

Reproduction

  • On release-v5.0 with ai 5.0.251, manually reusing tool-response messages caused both streamText and generateText to reject the expected continuation with AI_InvalidPromptError caused by AI_TypeValidationError.
  • The generated response retained startedAt and completedAt as own properties with undefined values; packages/ai/src/types/json-value.ts rejects those values, and packages/ai/src/prompt/standardize-prompt.ts reports the misleading ModelMessage[] error.
  • JSON serialization stripped the undefined properties and made both follow-up calls succeed, showing that retained undefined values—not heterogeneous arrays with missing keys—are the actual failure condition.
  • Replacing the values with null succeeded, and automatic multi-step execution using stopWhen: stepCountIs(2) also succeeded.
  • The runnable regression reproduction is examples/ai-functions/src/reproduction/issue-10893-undefined-tool-result-array.ts, supported by examples/ai-functions/package.json, examples/ai-functions/tsconfig.json, and pnpm-lock.yaml; it expects manual continuation to succeed but observes both APIs rejecting it.

Related Issues

Reproduces #10893

Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com>

@aayush-kapoor aayush-kapoor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants