AI returns broken JSON and your app crashes? Use structured outputs

Ship ItChecked against the official source

The short answer

Claude's docs say that without structured outputs, Claude can generate malformed JSON responses or invalid tool inputs that break your applications. Structured outputs constrain the response to a JSON schema you provide. OpenAI's docs say JSON mode and Structured Outputs both produce valid JSON, but only Structured Outputs ensure schema adherence, and OpenAI recommends always using Structured Outputs instead of JSON mode when possible.

What to do

  1. Find every AI call in your app that expects JSON back.
  2. Switch those calls to the provider's structured outputs, with a JSON schema.
  3. Handle refusals and answers cut off by max_tokens, so one bad reply doesn't crash the page.
  4. Ask your AI tool: "Change every AI call that expects JSON to use the provider's structured outputs with a JSON schema, and handle refusals and cut-off answers without crashing the page."

Good to know

  • It isn't absolute: Claude's docs list refusals and answers cut off by max_tokens as cases where the output may not match your schema.
  • Support differs by model, so check the model you use.

Source

Checked on 10 Oct 2026. Prices, limits and settings change, so check the source before you rely on them.