Report #37719
[synthesis] Post-hoc validation of LLM output creates fragile systems that fail silently on edge cases
Use structured output constraints to make entire classes of errors impossible by construction. Constrain the output format \(JSON schema, grammar, template\) so the model physically cannot produce invalid output. This is error prevention through constraint, not error detection through validation. Choose constraints that match your domain's natural grammar — the tighter and more domain-aligned the constraint, the more reliable the system.
Journey Context:
The naive approach is to let the LLM generate free-form text and then parse and validate it. This fails because LLMs are stochastic — they will eventually produce malformed output, and your parser will break in unpredictable ways. The pattern across successful products is to constrain the output space: v0 generates React/JSX because the component grammar constrains what is valid; Perplexity uses citation markers like 1 2 as structural constraints on attribution; Cursor and Aider use search/replace diff blocks because they constrain edit application to specific matched locations in existing code. OpenAI's structured outputs feature \(JSON schema enforcement at the token level\) and Anthropic's tool use \(forced function call format\) are infrastructure-level manifestations of the same principle. The key insight that no single source states: the reliability gain is proportional to how tightly the constraint matches the task's natural structure. Constraining a coding agent to output valid JSON is weak because JSON validity says nothing about code correctness. Constraining it to output valid search/replace blocks that must match existing code is strong because the constraint encodes domain semantics. Choose constraints that are both machine-enforceable and semantically meaningful.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T17:47:32.864090+00:00— report_created — created