zod icon indicating copy to clipboard operation
zod copied to clipboard

Add support for extending zod error messages from existing objects

Open anthonyalayo opened this issue 8 months ago • 6 comments

I have a zod object that is handed to me from elsewhere, and I do not have the ability to change it. However, I do know what items it contains. For example, it has a "firstName" string with a min length of 3 and a max length of 24.

I believe at present there is no way to do something like:

import { alreadyMadeSchema } from 'external-schema-provider';

...

const updatedSchema = alreadyMadeSchema.update({
firstName.min.3: "too short",
firstName.max.24: "too long"
});

Could support be added for such a feature?

anthonyalayo avatar Mar 28 '25 20:03 anthonyalayo

Hi, @anthonyalayo. I'm Dosu, and I'm helping the Zod team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • You requested a feature to enhance error messages for immutable Zod schemas.
  • Proposed a method to update error messages for specific constraints, such as string length, without altering the original schema.
  • Seeking support for implementing this functionality to improve schema validation feedback.
  • No comments or developments have occurred on this issue yet.

Next Steps:

  • Please let me know if this issue is still relevant to the latest version of the Zod repository. You can keep the discussion open by commenting on the issue.
  • If no updates are provided, the issue will be automatically closed in 14 days.

Thank you for your understanding and contribution!

dosubot[bot] avatar Jul 24 '25 16:07 dosubot[bot]

Yes, it is still relevant to the latest version of Zod.

anthonyalayo avatar Jul 24 '25 16:07 anthonyalayo

Hi @colinhacks, the user @anthonyalayo has confirmed that the feature request for enhancing error messages for immutable Zod schemas is still relevant. Could you please assist them with this issue? Thank you!

dosubot[bot] avatar Jul 24 '25 16:07 dosubot[bot]

@colinhacks could I get some feedback on this?

anthonyalayo avatar Oct 30 '25 16:10 anthonyalayo

@colinhacks could you please take a look at this issue? The user @anthonyalayo has indicated it is still relevant and would appreciate some feedback.

dosubot[bot] avatar Oct 30 '25 16:10 dosubot[bot]

+1, this is still relevant. Many tools generate Zod schemas and as consumers we could inspect and extend it. But simple config updates without changing schema shape would be a nice feature.

arfath-linklet avatar Nov 03 '25 00:11 arfath-linklet