One schema, many consumers
The output schema is consumed by: the prompt (in the JSON Schema export), the validator (Pydantic / Zod), the downstream code (TypeScript / Python types), the test suite (sample fixtures), and the docs (whatever describes the API). One source of truth, many derived artifacts.
How to wire it
- Author in Pydantic (Python) or Zod (TypeScript).
- Generate JSON Schema via
model_json_schema()orzodToJsonSchema. - Inject the JSON Schema into the prompt as a structured-output spec.
- Validate the response with the same Pydantic / Zod model.
- Type the consumer with the same type.
The win
When you change the schema, every dependent layer breaks at compile time. You see what needs to change. Without a single source of truth, schema changes silently desync — prompt asks for old shape, code expects new shape, runtime crashes.