parse() vs safeParse() in Zod

From the Zod cheat sheet ยท Parsing & Error Handling ยท verified Jul 2026

parse() vs safeParse()

Throwing and non-throwing parse methods

typescript
// parse - throws on error
try {
  const user = UserSchema.parse(data);
} catch (err) {
  if (err instanceof z.ZodError) {
    console.log(err.issues);
  }
}

// safeParse - returns result object
const result = UserSchema.safeParse(data);
if (result.success) {
  console.log(result.data);
} else {
  console.log(result.error.issues);
}
๐Ÿ’ก Prefer safeParse() in API routes โ€” no try/catch, cleaner control flow
โšก z.flattenError() is perfect for form validation โ€” gives field-level error arrays
๐Ÿ“Œ Use parseAsync() when your schema has async refinements like database lookups
๐ŸŸข ZodError.issues is an array โ€” each issue has code, path, message for granular handling
parsesafeParseerrors

More Zod tasks

Back to the full Zod cheat sheet