Skip to content

feat(message-validator): include more details in error messages#6133

Merged
samdenty merged 4 commits intomainfrom
feat/more-helpful-error-messages
May 6, 2025
Merged

feat(message-validator): include more details in error messages#6133
samdenty merged 4 commits intomainfrom
feat/more-helpful-error-messages

Conversation

@samdenty
Copy link
Copy Markdown
Contributor

@samdenty samdenty commented May 3, 2025

Background

Before in issues like #5499 & #5833, if users ran into an issue where the messages array failed to parse correctly they'd run into a difficult to debug error Invalid prompt: messages must be an array of CoreMessage or UIMessage

Summary

This PR extends these error messages to include more details on what exactly went wrong, which is useful information for debugging when stuff breaks.

On security: I think this is an okay change since the data sent is not private

Verification

E2E tests validating new error messages

Tasks

  • 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)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Future Work

Related Issues

prompt,
message: 'messages must be an array of CoreMessage or UIMessage',
message: [
'messages must be an array of CoreMessage or UIMessage',
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.

maybe change msg to "message must be a CoreMessage or a UI message" and consider changing the InvalidPromptError so that the messages can be included and printed instead

Copy link
Copy Markdown
Collaborator

@lgrammel lgrammel left a comment

Choose a reason for hiding this comment

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

Best practice is to include the raw information (messages, message) in the error object, vs adding to the error message itself.

@samdenty
Copy link
Copy Markdown
Contributor Author

samdenty commented May 4, 2025

Best practice is to include the raw information (messages, message) in the error object, vs adding to the error message itself.

Yep I was unsure on the best way to approach this problem. The issue is what if it throws it inside the stream, so it ends up being serialised as a data stream message - in that case what is the best way to surface the error message to the user. Do the errors get printed to the console terminal output automatically? If not, should we print the messages there? What about if people run into this on production, how best can we allow for this error to be fixed by the application. I imagine they'd have error reporting built into the stack somewhere, it's just a question of how we hook that up correctly (and what methods they use)

I also want to make sure if we do this, that there's no possibility of leaking the system prompt as the user could malform a message.

@samdenty samdenty merged commit a295521 into main May 6, 2025
8 checks passed
@samdenty samdenty deleted the feat/more-helpful-error-messages branch May 6, 2025 13:32
jacobkerber pushed a commit to jacobkerber/ai that referenced this pull request Jul 15, 2025
…el#6133)

## Background

Before in issues like vercel#5499 &
vercel#5833, if users ran into an
issue where the messages array failed to parse correctly they'd run into
a difficult to debug error `Invalid prompt: messages must be an array of
CoreMessage or UIMessage`

## Summary

This PR extends these error messages to include more details on what
exactly went wrong, which is useful information for debugging when stuff
breaks.

On security: I think this is an okay change since the data sent is not
private
jacobkerber pushed a commit to jacobkerber/ai that referenced this pull request Jul 15, 2025
…el#6133)

Before in issues like vercel#5499 &
vercel#5833, if users ran into an
issue where the messages array failed to parse correctly they'd run into
a difficult to debug error `Invalid prompt: messages must be an array of
CoreMessage or UIMessage`

This PR extends these error messages to include more details on what
exactly went wrong, which is useful information for debugging when stuff
breaks.

On security: I think this is an okay change since the data sent is not
private
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants