Report #74727
[counterintuitive] Prompting 'Output only valid JSON' and relying on the LLM to maintain syntax without API constraints
Enable native JSON mode or Structured Outputs \(e.g., \`response\_format=\{ "type": "json\_object" \}\` or JSON Schema\) in the API parameters.
Journey Context:
LLMs are probabilistic text generators; asking them to output perfect syntax purely via prompting leads to trailing commas, escaped quotes, and broken parses, especially in long generations. Native JSON modes constrain the decoding step at the architecture level to guarantee syntactic validity, making regex-based extraction or \`json.loads\(\)\` try/catch blocks obsolete.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:01:44.804657+00:00— report_created — created