New Tool Radar

AI Concepts

How to Fix a Model That Ignores a JSON Schema Format

Fix a model that ignores a JSON Schema format by checking support, simplifying the schema and switching to Structured Outputs.

Schematic illustration of fix a model that ignores a json schema format: step one check the model supports it, step two simplify the schema, step three switch to structured outputs.

A model that returns free text when you asked for JSON is usually not disobeying you: it is using a model or a mode that does not enforce the schema. JSON mode only guarantees valid JSON, and a prompt asking for JSON guarantees nothing. Work through the causes in order: support, schema, then mode, and the format will hold.

Prerequisites

  • The model and API you are using.
  • The schema you sent, and the reply that ignored it.
  • The Structured Outputs guide open for the supported subset.

Steps

Step 1: Check the model supports it

Check that the model supports Structured Outputs: it is available in the latest large models, starting with GPT-4o, and older models may only offer JSON mode. If the model does not support it, switch models or accept JSON mode with validation in code.

Step 2: Simplify the schema

Simplify the schema to the supported subset: a root object, required properties, additionalProperties false, and supported types. A schema with an unsupported keyword can be rejected or ignored, so remove the advanced parts first.

Step 3: Switch to Structured Outputs

Send the schema as the response format, json_schema in Chat Completions or text.format in the Responses API, instead of asking for JSON in the prompt text. Then validate the reply against the schema in code.

Worked example: Northgate Clinic appointment extract

The fictional Northgate Clinic asks a model for appointment records as JSON. The first reply is free text.

Attempt What changed Reply Result
1 Asked for JSON in the prompt Free text Failed
2 JSON mode, no schema Valid JSON, missing a field Failed
3 Structured Outputs with schema JSON matching the schema Passed

The prompt-only attempt gives free text, JSON mode gives valid JSON with a missing field, and Structured Outputs gives JSON matching the schema, so the clinic uses Structured Outputs.

Expected result. The reply matches the schema after the mode is switched to Structured Outputs, with the cause of each earlier failure recorded. UNTESTED: this guide was not run against a live model or API. The worked example below is fictional practice material, and its result is the expected result, not a measured one.

Limits

  • Structured Outputs still allows refusals and truncated replies; handle those in code.
  • A schema that is too complex can fail even on a supporting model; keep it simple.
  • This guide does not cover function calling, which is another way to get structured data.

Sources

See all