Skip to content

Conversation

@AVtheking
Copy link
Contributor

Background

The validateUIMessages and safeValidateUIMessages functions don't properly check for arrays being not-empty,

Summary

Updated the zod schema to catch empty arrays passed in messages.

Manual Verification

Wrote tests with empty arrays throwing errors, this should be sufficient right ?

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)

Related Issues

Fixes #10003

@gr2m gr2m added bug Something isn't working as documented ai/core backport labels Nov 9, 2025
@gr2m gr2m self-assigned this Nov 9, 2025
Copy link
Collaborator

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

I wonder if this is worth validating with zod, or if we should update this check here (or add a new check)

if (messages == null) {

@AVtheking
Copy link
Contributor Author

I wonder if this is worth validating with zod, or if we should update this check here (or add a new check)

if (messages == null) {

Yeah could update here also, but I thought zod is already being used for validation so it should be good.

Also this null check would also be caught by zod isn't it ? I assume reason being checking this separately is to provide clear error message, which is for non empty array is provided by zod

@gr2m
Copy link
Collaborator

gr2m commented Nov 10, 2025

you know what let's just go ahead. If for some reason a dedicated check will be better we can change that later

@gr2m gr2m merged commit eb8d1cb into vercel:main Nov 10, 2025
28 of 29 checks passed
vercel-ai-sdk bot pushed a commit that referenced this pull request Nov 10, 2025
@vercel-ai-sdk vercel-ai-sdk bot removed the backport label Nov 10, 2025
@vercel-ai-sdk
Copy link
Contributor

vercel-ai-sdk bot commented Nov 10, 2025

⚠️ Backport to release-v5.0 created but has conflicts: #10117

gr2m added a commit that referenced this pull request Nov 10, 2025
This is an automated backport of #10093 to the release-v5.0 branch

---------

Co-authored-by: ANKIT VARSHNEY <132201033+AVtheking@users.noreply.github.com>
Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/core bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

validateUIMessages doesn't catch empty arrays

2 participants