Structured Output From Local LLMs: JSON That Never Breaks (Ollama + Zod) A developer created a TypeScript helper, generateStructured(schema), that combines Ollama's native JSON modes with Zod validation to produce reliable structured output from local LLMs. The approach uses Ollama's format parameter with JSON Schema derived from Zod schemas via zod-to-json-schema, reducing parse failures on small models. The helper also includes retry loops and repair logic for truncated output, addressing common issues like missing closing braces or markdown fences. A 1.5B model running on your laptop will return JSON that almost parses. The closing brace is missing. A trailing comma sneaks in. The whole thing is wrapped in a markdown fence with a chirpy "Sure Here's your JSON:" on top. Cloud models do this too, but small local models do it constantly, and that is exactly where most "just prompt it harder" advice falls apart. I wrote about validating LLM responses with Zod https://pavelespitia.hashnode.dev before: schemas as contracts, safeParse , extracting JSON from chaos. That post is the foundation. This one is the local-model-specific layer on top: Ollama's native JSON modes, retry loops that actually converge, repairing truncated output, and a single generateStructured