kwj.ai · acquisition inquiries from >$999view prospectus →
The Domesday Book ofKWJ · AI

Engineering · 7 min

Structured outputs and the JSON-adherence problem

Getting reliable JSON out of an LLM is now table-stakes. The pitfalls are real.

By C.W. Jameson · Published 19 May 2026 · Last reviewed 19 May 2026

Structured-output APIs are the modern solution. Every frontier provider offers them, and they reach 99%+ adherence on well-formed schemas. The remaining 1% is where production breaks. This guide is about that 1%.

Use the API, not the prompt

Prompting a model to 'output JSON' produces 90% adherence. The structured-output API produces 99.5%. Use the API.

Schema design

Make required fields actually required. Make enums actually enumerated. Anticipate edge cases: null vs empty string, integer vs string, optional fields.

The remaining 0.5%

Production code that doesn't validate is production code that crashes. Always validate post-parse. Always log validation failures.

Frequently asked

What about Pydantic?

OpenAI and Anthropic SDKs both accept Pydantic models as schema sources. The integration is clean.

Partner offer

Anthropic's Claude family is the model lineage most operators end up on for serious agent work. The free tier remains useful.

Try Claude →

Affiliate link — see disclosure.

From the Almanac shop

The Operator's Compendium

Every agent harness, every routing pattern, every cost trick. 90-page PDF.

$29Coming soon

All guides