fix(ai): improve type validation error messages with field paths and entity identifiers#12106
Merged
felixarntz merged 2 commits intomainfrom Jan 29, 2026
Merged
fix(ai): improve type validation error messages with field paths and entity identifiers#12106felixarntz merged 2 commits intomainfrom
felixarntz merged 2 commits intomainfrom
Conversation
4 tasks
gr2m
approved these changes
Jan 28, 2026
|
|
||
| if (metadataSchema) { | ||
| for (const message of validatedMessages) { | ||
| for (const [msgIdx, message] of validatedMessages.entries()) { |
Collaborator
There was a problem hiding this comment.
TIL - nice way to get the index in a for loop
Collaborator
|
@felixarntz and I tested with
✅ good to go |
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
Validation errors from
safeValidateUIMessagesand streaming validation lacked context about what was being validated, making debugging difficult.Before:
After:
Alternative to #10154: This PR focuses on addressing the lack of context closer to the root, and includes the full field identifier to help finding the culprit more quickly.
Summary
Added optional context tracking to
TypeValidationErrorto include field paths (e.g.,messages[0].parts[1].data) and entity identifiers (e.g., message ID, tool call ID) in validation error messages.Approach:
TypeValidationContextinterface withfield,entityName, andentityIdpropertiesTypeValidationErrorand validation utilities to accept and format contextvalidate-ui-messages.tsandprocess-ui-message-stream.tsto provide context with index trackingThe change is backward compatible (context is optional) and includes a minor performance improvement by consolidating data/tool validation into a single loop.
Manual Verification
To verify the improved error messages:
Checklist
pnpm changesetin the project root)Future Work
Issue #10137 also mentions fixing documentation for metadata schema examples. That's not the primary issue raised though, and will be addressed in a separate PR.
Related Issues
Fixes #10137