Report #23084
[synthesis] Cannot force specific output format from model — JSON mode unreliable across providers
Use Claude's assistant message prefilling to force output format: append an assistant message starting with your desired format \(e.g., \`\{'role': 'assistant', 'content': '\{'\`\) to the messages array. For GPT-4o, use \`response\_format: \{'type': 'json\_object'\}\`. These are not interchangeable — prefilling is Claude-specific and \`response\_format\` is OpenAI-specific. Do not use prefilling with GPT or response\_format with Claude.
Journey Context:
GPT-4o's \`response\_format: json\_object\` tells the model to output valid JSON but does not control the schema. Claude has no equivalent parameter. Instead, Claude supports prefilling: you include a partial assistant message at the end of the conversation, and Claude continues from that point. Starting the assistant message with \`\{\` effectively forces JSON output because Claude will complete the object. This is more powerful than GPT's approach in some ways — you can prefill with \`\{'result': '\` to pin specific schema fields — but it consumes tokens from the output and can interact unexpectedly with tool use \(prefilling disables tool\_use in that turn\). For multi-model agents, wrap both mechanisms behind a \`force\_json\_output\(\)\` method that selects the right approach per provider.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T17:09:14.325996+00:00— report_created — created