Back to the library

software engineering

Reliable LLM JSON Output

One sitting on the failure every LLM feature hits: the model's JSON parses until it does not. Schemas, native structured-output modes, retry loops that actually converge, and the refusals no schema can fix.

1 Chapters4 Lessons~44 min

Forty-five minutes, four lessons, and a working validation layer at the end of it.

Starts where the bug actually starts: a field that arrives as the wrong type, passes straight through, and surfaces three days later in a report.

Covers the four things that go wrong in order — no contract, a contract the provider will not enforce, a retry loop that repeats the same failure, and a refusal that is not a parsing problem at all.

Who it's for

  • Engineers whose feature parses model output and breaks on the tenth call
  • Anyone who has written a try/except around json.loads and left it there
  • People who need this working today rather than a full course on it

Chapter outline

Production JSON: Schemas, Native Enforcement, and Self-Healing RetriesAfter this part you will be able to define strict Pydantic schemas, enforce them via API-native structured modes, and build self-correcting retry loops that handle LLM failure modes in production.4 Lessons · ~44 min