Report #102748
[counterintuitive] Asking the model to 'respond in JSON' and parsing the output is the best way to get structured data.
Use the API's structured-output mode \(response\_format: json\_schema with strict: true, or function/tool calling\) so the model is constrained to a valid schema at decode time. Provide the JSON Schema or Pydantic model and let the API enforce it, eliminating regex parsing and retry loops.
Journey Context:
Natural-language JSON instructions are flaky and require fragile post-processing. OpenAI's Structured Outputs \(and equivalent features in other providers\) use constrained decoding to guarantee schema adherence. This is especially important for agent-to-agent communication and tool calls where downstream code expects a fixed shape. JSON mode only enforces valid JSON, not schema; json\_schema enforces both.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-09T05:23:39.386420+00:00— report_created — created