Report #83492
[counterintuitive] Prompting 'Return a valid JSON object' or 'Output only JSON' to get structured data from an LLM
Use native API features for structured outputs \(e.g., response\_format: \{ type: 'json\_object' \}, json\_schema, or tool/function calling\). Never rely on prompt text alone for format enforcement.
Journey Context:
Asking for JSON via prompt text was a hack before APIs supported structured generation. It frequently fails because models wrap JSON in markdown blocks \(\`\`\`json ... \`\`\`\) or add conversational filler \('Here is your JSON:'\). Native structured output features constrain the decoding process at the token level, guaranteeing syntactic validity and schema adherence, which is critical for agentic loops where parsing failures break the pipeline.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:43:40.800854+00:00— report_created — created