© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
5 replies
zeekrey

Custom error messages with drizzle-zod?

Hey there! 👋 Does somebody know how to add custom error messages to a schema created via
createInsertSchema
createInsertSchema
? I know I can refine the schema by passing an object as the second argument, but since the error messages are part of the actual type definition, I would be repeating myself like so:

export const users = sqliteTable("users", {
  id: integer("id").primaryKey().notNull()
});

const zodSchema = createInsertSchema(users, {
  id: (schema) => schema.id.number({
    required_error: "Id is required",
    invalid_type_error: "Id must be a number",
});
export const users = sqliteTable("users", {
  id: integer("id").primaryKey().notNull()
});

const zodSchema = createInsertSchema(users, {
  id: (schema) => schema.id.number({
    required_error: "Id is required",
    invalid_type_error: "Id must be a number",
});
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

drizzle-zod with custom types
Drizzle TeamDTDrizzle Team / help
3y ago
Drizzle-zod combined with regular zod? 🙃
Drizzle TeamDTDrizzle Team / help
15mo ago
Drizzle Zod with relations
Drizzle TeamDTDrizzle Team / help
2y ago
Help with Drizzle-zod
Drizzle TeamDTDrizzle Team / help
3y ago