- Category: C. AI Engineering & LLM Ops
- English term: Structured Output and JSON Contract
- Related: Schema Validation · Independent Verification (Verifier) · Grounding and Source Verification · Pipes and Filters Pattern (Pipeline Architecture) · Exit Code Contract
General Meaning
Because LLMs are probabilistic models designed to generate natural language, unguided responses often include conversational filler such as greetings or explanatory preamble. When free-form text mixes into an output consumed by a downstream program or API, parsing errors occur and halt the automated pipeline.
Structured Output and JSON Contracts specify a strict schema via prompts and inference parameters, constraining the LLM to emit pure JSON. Downstream programs can mechanically validate whether the response fulfills the contract, enabling resilient automated pipelines.
Why It Matters
- Automating pipeline integration: Allows downstream scripts and databases to ingest data directly without fragile regular-expression parsing.
- Enabling deterministic validation: Schema validators can immediately check required keys, data types, and value ranges mechanically.
- Suppressing hallucinations: Narrows the room for free-form prose and forces the model to focus strictly on populating designated fields, preventing fabrication and digression.
How the Site Factory Uses It
In the Site Factory, the shared pipeline contract (ops/pipeline_contract.md) mandates that all LLM responses across automated components and AI workers use strict JSON formats. For example, reviewers (engine/review.py) output {"reviewer": "...", "ok": false, "findings": [{"id": "...", "severity": "block", "where": "...", "what": "...", "hint": "..."}]}, rejecting any malformed output immediately; information extraction (engine/extract.py) generates drafts (drafts.json) matching fields in design.json with "think": false, holding rows with missing required fields or invalid types in candidates.json.
Similarly, AI pre-review (tools/operator_review.py) writes structured records to ops/operator_reviews/<id>.json (case_id, decision_request, reason, evidence), holding decisions until completion logs and evidence are verified. Reviewer severity levels are strictly defined as block (do not publish until fixed), fix (repair or remove if unfixable), and note (informational), and LLMs only exchange JSON data without executing shell commands, upholding the principle of least privilege.
Caveats & Operational Rules
- Syntactic validity is not semantic truth: Successfully parsing a JSON object does not guarantee that the numbers or facts inside are accurate; the Site Factory always runs
check_sources.pyafter parsing to verify facts against source text. - Guard against markdown code fences: Some models wrap JSON in markdown fences like ```
`json```; enforce pure JSON via API formatting parameters or strip fences safely in the parser. - Never let the LLM manipulate the OS directly: Mediating interactions through a JSON contract ensures that only deterministic host code executes safe system or database operations.
Related Terms
- Schema Validation
- Independent Verification (Verifier)
- Grounding and Source Verification
- Pipes and Filters Pattern (Pipeline Architecture)
- Exit Code Contract
References
- Book: Martin Kleppmann, "Designing Data-Intensive Applications", Chapter 4 (Encoding and Evolution)
Verified: 2026-11-08