What this thread does
Do first: call schema.safeParse(input, { reportInput: false }) before application logic, using await schema.safeParseAsync(...) if any refinement or transform is asynchronous.
Short answer
As of November 2026, Zod 4.6.7 is the release baseline; the linked current docs describe the boundary APIs. Consume only result.data on success. On failure, return selected messages and field paths, not the request or the whole exception (basics).
Choose / don't choose
z.strictObject: choose when unexpected keys indicate an invalid contract or typo; don't silently discard keys the caller must correct.z.object: choose when ignoring extra fields is the intended contract; it strips unknown keys from parsed output by default. Don't pass the original input downstream after parsing (schema API).- Nested tree: choose
z.treeifyErrorfor nested error objects; don't flatten array positions into an ambiguous field name (formatting).
Not for: legacy slug normalization; see hono-zod-canonical-slug-legacy-normalization.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
error | Fixed string or an issue-to-message function that does not echo input | Current Zod schema APIs | customization |
reportInput | Input data omitted by default; true adds rejected input to issues | Per-parse options | customization |
z.strictObject(shape) | Reject unknown keys; select for closed request contracts | Current object API | schemas |
z.object | Strip unknown keys by default | Current object API | schemas |
Disabling input reporting does not sanitize custom messages: never interpolate iss.input into a response. Schema-level error customization takes precedence over a per-parse error map (customization).
Order of operations
1. Parse before performing writes or using request values. Await safeParseAsync when the schema uses asynchronous APIs like async refinements or transforms (basics). 2. Narrow on result.success. On false, call const tree = z.treeifyError(result.error); each node's errors applies at that node, properties descends through objects and items through array indices. Preserve root errors as well as field errors; use optional chaining for absent nodes (formatting). 3. On true, pass only result.data to application code. Exercise nested invalid fields, an unknown key, and an async rejection in boundary acceptance cases.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
Encountered Promise during synchronous parse. Use .parseAsync() instead. | A synchronous parse reaches an asynchronous check | Await safeParseAsync for result-style handling; handle operational exceptions separately | Zod source, basics |
Unrecognized key: "extraKey" | Strict object receives an undeclared property | Correct the request; choose stripping only if deliberately part of the contract | formatting example |
MarinoBenassai's September 2, 2025 report, closed on September 1, 2026 as not planned, reported that the resulting ZodErrorTree uses the schema output type instead of the input type. Keep boundary field validation before such transforms, or explicitly model the error-view type; a successful TypeScript property access does not establish a runtime error path.
Missing
- The linked source does not confirm: the literal customization example { error: "Invalid field" }.
- No domain-specific field labels, localization policy or HTTP status contract is specified.
reportInput: falsedoes not remove sensitive property names or details deliberately placed in messages.
Started from a post by @Zod, packaged by the editor. Original post