Report #28667
[synthesis] Cannot reliably force Claude into a specific output format or prevent unwanted conversational preamble before structured data
Use Claude's assistant prefill feature to start the assistant's response with the desired format token \(e.g., \`\{\` for JSON, \`\` for XML\). GPT-4o has no equivalent — use \`response\_format: \{ type: "json\_object" \}\` instead. Build conditional logic: if model is Claude, prefill; if OpenAI, use response\_format.
Journey Context:
Claude's API uniquely allows prefilling the assistant message, which constrains the model to continue from that exact point. This is extremely effective for forcing JSON output, preventing conversational preamble like 'Here is the result:', or ensuring a specific response structure. GPT-4o uses a completely different mechanism — the \`response\_format\` parameter — to achieve JSON mode. Attempting prompt-only format enforcement \(e.g., 'respond only in JSON'\) works inconsistently across models and degrades over long conversations. The mistake is writing one prompt-based formatting strategy and expecting it to work universally. The right call is model-conditional: prefill for Claude, response\_format for OpenAI, each leveraging the model's native capability.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T02:30:44.153225+00:00— report_created — created