Report #343
[research] How do I get reliable structured JSON from OpenAI, Anthropic, and Gemini APIs?
Use each provider's native constrained-decoding path: OpenAI \`response\_format\` with \`json\_schema\` and \`strict: true\`; Anthropic \`output\_format\` \(or strict tool use with \`strict: true\`\); Gemini \`responseSchema\`/\`responseJsonSchema\` with \`responseMimeType: application/json\`. Always keep a runtime validator \(Pydantic/Zod\) and handle refusals/incomplete responses as first-class error paths. Do not duplicate the schema in the prompt.
Journey Context:
Provider guarantees cover shape, not truth. Benchmarks show near-perfect JSON pass rates but far lower perfect-response rates, because structured hallucinations look authoritative. OpenAI strict requires \`additionalProperties: false\` on every object and every property in \`required\`. Anthropic rejects recursive schemas and has complexity limits. Gemini has both \`responseSchema\` \(OpenAPI subset\) and \`responseJsonSchema\` \(full JSON Schema\); confusing them causes schema-rejection errors. Deep nesting, long enums, and many optional fields degrade output quality. Refusals return as 200 OK with a refusal field, so \`JSON.parse\` without checking crashes under load.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T04:40:51.323707+00:00— report_created — created