You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, when a parse fails, the output message now prioritizes zod issues by formatting each issue as a line with its message and associated path. This is in line with zod's prettify and the current approach on main branch
Motivation and Context
Currently, when a parse against an input or output schema fails, the default value error.message that is used is unclear and bloated. In addition, with zod4, we cannot assume that error.message will have all the zod issues aggregated properly under it. Reference this for more details: #1415
How Has This Been Tested?
I built the package and tested it in my mcp-based project by sending tool call requests that will fail, the output is a set of lines each representing a zod-issue, with custom messages appearing clearly. For example:
Invalid input: expected string, received undefined at path personalData.dateOfBirth
Invalid country of birth at path personalData.countryOfBirth <--- custom error
Unrecognized key: "termAndConditions" at object root
Breaking Changes
There should not be any breaking changes. If some mcp-client implementations are making assumptions about error output for InvalidParams 32602 errors and running special logic based on that, they may run into issues. But I would not think that its the case since the error output format was previously also prone to vary.
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
One thing to clarify in this PR is how strict and detailed do we want to be about path formatting? For issues with array schemas there will be an index (number) in the path array, and zod additionally handles symbols as well as somehow { key: string | number | symbol } types, which would do not seem common to me. But handling numbers is probably worthwhile using something like:
const dotPath = i.path.reduce((acc, seg, index) => {
if (typeof seg === "number") return `${acc}[${seg}]`;
index === 0 ? `${seg}` : `${acc}.${seg}`;
}, '');
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
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.
By default, when a parse fails, the output message now prioritizes zod issues by formatting each issue as a line with its message and associated path. This is in line with zod's prettify and the current approach on main branch
Motivation and Context
Currently, when a parse against an input or output schema fails, the default value error.message that is used is unclear and bloated. In addition, with zod4, we cannot assume that error.message will have all the zod issues aggregated properly under it. Reference this for more details:
#1415
How Has This Been Tested?
I built the package and tested it in my mcp-based project by sending tool call requests that will fail, the output is a set of lines each representing a zod-issue, with custom messages appearing clearly. For example:
Breaking Changes
There should not be any breaking changes. If some mcp-client implementations are making assumptions about error output for InvalidParams 32602 errors and running special logic based on that, they may run into issues. But I would not think that its the case since the error output format was previously also prone to vary.
Types of changes
Checklist