How to use
- Paste a JSON sample.
- Set the schema name — you get
NameSchemaandtype Name = z.infer<typeof NameSchema>. - Keys missing from some array items become
.optional(), and mixed nulls become.nullable(). - Use the schema with
generateObject()in the AI SDK,zodResponseFormat()in the OpenAI SDK, or.parse()anywhere.
FAQ
Does it support Zod 4?
Yes. The output only uses core APIs (z.object, z.array, z.union, .optional(), .nullable()) that are the same in Zod 3 and Zod 4.
Why use Zod for LLM output?
Models occasionally return malformed or unexpected JSON. Validating with Zod gives you a typed object or a clear error you can retry on, instead of a crash somewhere deeper in your app.