How do you make JSON output reliable?
IntermediateConceptPrompting & structured outputs
Answer
Use the provider's structured-output or JSON-schema mode where available, give the exact schema, keep temperature low, and validate the response in code with a schema validator. On validation failure, retry once with the error message included, then fall back safely rather than crashing.