Report #93580
[architecture] LLM generating invalid JSON or hallucinating fields breaking typed contracts
Use constrained decoding \(outlines, jsonformer, or OpenAI function calling\) to force valid JSON schema at generation time, not post-hoc validation
Journey Context:
Post-hoc regex repair is fragile - 'fix this broken JSON' is another LLM call with latency/cost. Common mistake is hoping few-shot prompting ensures validity. Constrained decoding masks logits to only allow tokens valid for the schema. For open models, use outlines/jsonformer; for OpenAI, use strict function calling. This guarantees type safety at the boundary without runtime validation failures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:39:40.381480+00:00— report_created — created