{"slug": "structured-output-is-a-contract-not-a-request", "title": "Structured output is a contract, not a request", "summary": "A developer's team standardized structured output from language models by enforcing JSON schemas with validators rather than relying on prompts. The approach rejects invalid outputs and retries with error feedback, quarantining persistent failures for human review. The developer notes that schemas are effectively half the prompt, and tightening them reduces hallucinations.", "body_md": "The first thing we standardized when model calls entered our pipelines was the boundary. Every call whose output feeds a machine returns JSON against a schema, and the schema is enforced by an ordinary validator. Not by asking nicely in the prompt. By rejecting the output and making the model try again with the validator's error in its face.\n\n``` js\nasync function extract(input, schema, tries = 3) {\n  let feedback = '';\n  for (let i = 0; i < tries; i++) {\n    const raw = await llm({\n      system: RULES + feedback,\n      user: input,\n      response_format: schema,   // constrained decoding where the API supports it\n      temperature: 0,\n    });\n    const errors = validate(schema, raw);   // plain JSON Schema, same lib as our forms\n    if (errors.length === 0) return raw;\n    feedback = ' Previous output failed validation: ' + errors.join('; ');\n  }\n  return quarantine(input);   // a review queue. never a crash, never a guess.\n}\n```\n\nThree details carry most of the weight:\n\nThe item that fails three attempts is the interesting one. It goes into a review queue, a human labels it, and the labeled case joins the regression suite. Our schemas have been hardened by two years of their own rejects. Which points at the real lesson: the schema is half of the prompt. Most of our prompt engineering time is spent deleting fields, tightening types and closing enums, because every degree of freedom you remove from the output is a hallucination that can no longer happen.", "url": "https://wpnews.pro/news/structured-output-is-a-contract-not-a-request", "canonical_source": "https://dev.to/intframe/structured-output-is-a-contract-not-a-request-5cmb", "published_at": "2026-08-15 10:18:59+00:00", "updated_at": "2026-08-15 10:42:08.340190+00:00", "lang": "en", "topics": ["large-language-models", "developer-tools", "mlops"], "entities": [], "alternates": {"html": "https://wpnews.pro/news/structured-output-is-a-contract-not-a-request", "markdown": "https://wpnews.pro/news/structured-output-is-a-contract-not-a-request.md", "text": "https://wpnews.pro/news/structured-output-is-a-contract-not-a-request.txt", "jsonld": "https://wpnews.pro/news/structured-output-is-a-contract-not-a-request.jsonld"}}