feat(ai): add safeValidateUIMessages#8680
Merged
gr2m merged 5 commits intovercel:mainfrom Sep 18, 2025
Merged
Conversation
gr2m
reviewed
Sep 16, 2025
Collaborator
gr2m
left a comment
There was a problem hiding this comment.
could you add documentation as we have for validateUIMessages(): https://ai-sdk.dev/docs/reference/ai-sdk-core/validate-ui-messages
gr2m
reviewed
Sep 16, 2025
Collaborator
|
thanks for the pull request 👍🏼 if you could comment on the issue that you are working on, that would be great! For one, it allows us to assign the issue to you, and second people know that somebody is already working on it and won't duplicate your work |
1 task
lgrammel
reviewed
Sep 17, 2025
Contributor
Author
gr2m
approved these changes
Sep 18, 2025
vercel-ai-sdk bot
pushed a commit
that referenced
this pull request
Sep 18, 2025
## Background The current validateUIMessages throws on validation failure. For API endpoints and similar contexts it's ergonomically preferable to use a safe-return pattern (like zod's safeParse) to avoid try/catch and get a typed success/failure result. see context in #8673 ## Summary - Add `safeValidateUIMessages` - Returns a discriminated union: `{ success: true, data }` || `{ success: false, reason, error }` ## Manual Verification - Ran unit tests in packages/ai ## Tasks - [x] Tests have been added / updated (for bug fixes / features) - [x] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues fixes #8673 --------- Co-authored-by: Francisco Veiras <74626997+francisco-svg761@users.noreply.github.com> Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
Contributor
|
✅ Backport PR created: #8742 |
gr2m
added a commit
that referenced
this pull request
Sep 18, 2025
This is an automated backport of #8680 to the v5.0 branch. Co-authored-by: Francisco Veiras <74626997+fveiraswww@users.noreply.github.com> Co-authored-by: Francisco Veiras <74626997+francisco-svg761@users.noreply.github.com> Co-authored-by: Gregor Martynus <39992+gr2m@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.
Background
The current validateUIMessages throws on validation failure. For API endpoints and similar contexts it's ergonomically preferable to use a safe-return pattern (like zod's safeParse) to avoid try/catch and get a typed success/failure result.
see context in #8673
Summary
safeValidateUIMessages{ success: true, data }||{ success: false, reason, error }Manual Verification
Tasks
pnpm changesetin the project root)pnpm prettier-fixin the project root)Related Issues
fixes #8673