import { toJSONSchema, type z } from "zod"; /** * Serialises a Zod schema into a string the LLM can read in the prompt. * * Implementation: defers to Zod 4's built-in `z.toJSONSchema()`. The output * is standard JSON Schema, which LLMs handle natively AND carries the Zod * constraints (`minimum`, `maximum`, `default`, `enum`) that an LLM benefits * from seeing — e.g. the model picks `hours: 6` rather than `hours: 999` * when it sees `"maximum": 168` in the schema. * * The wrapper is the formatter. If Zod's JSON Schema output ever shifts * shape between releases, the change is contained here; the public API * (`printSchema(schema): string`) and the LLM-facing prompt format stay * stable unless we deliberately change them. */ export function printSchema(schema: z.ZodType): string { return JSON.stringify(toJSONSchema(schema), null, 2); }