Why prompting for JSON in prose isn't enough
Telling a model "respond in JSON" gets you JSON most of the time — and the rest of the time you get a Markdown code fence around it, a chatty preamble ("Sure! Here's the JSON:"), a trailing comma, or an unescaped quote. At scale, even a 1% malformed rate breaks a pipeline.
The fix is to constrain generation, not just request it. Both OpenAI and Claude expose modes that force the output to be valid JSON: OpenAI's structured outputs / JSON mode via the Chat Completions API, and Claude's tool-use / structured output described in the Claude prompt engineering overview. For the broader design tradeoffs, see our guides on structured output schema design and function calling vs. structured output.