Zod Schemas as Output Contracts A developer demonstrates how Zod schemas can serve as output contracts for AI models, unifying runtime validation, TypeScript types, JSON Schema generation, and repair instructions. The approach uses Zod 4's built-in z.toJSONSchema() and distinguishes between malformed JSON and schema mismatches for effective error handling. A model returns a string. Your component needs an object. Everything between those two sentences is where AI features break in production, and one Zod schema can own all of it: the constraint sent to the model, the validation of what comes back, the error text that drives a repair, and the TypeScript type the component consumes. js // schema.ts import { z } from "zod"; export const Ticket = z.object { title: z.string .min 3 .max 120 , severity: z.enum "low", "medium", "high", "critical" , component: z.enum "auth", "billing", "search", "api", "ui", "other" , steps to reproduce: z.array z.string .min 1 .max 8 , affects users: z.boolean , // Nullable rather than optional: a model that is unsure should say null // explicitly. An absent key and an unknown value look identical otherwise, // and you cannot tell "did not answer" from "answered nothing". estimated hours: z.number .min 0 .max 200 .nullable , } ; export type Ticket = z.infer