AIToday
Large Language ModelsAI Coding AssistantsZenn AI/MLPublished: Nov 7, 2026, 19:01 JST

JSON Schema won't fix bad AI answers: a guide to structured output

Send on LINE
JSON Schema won't fix bad AI answers: a guide to structured output

3 Key Points

  1. What happened

    The guide shows a support-ticket example where a free-text reply like "this is about returns" is replaced by JSON with a category field and reason field, constrained by a JSON Schema using type, properties, enum, required, and additionalProperties: false.

  2. Why it matters

    A reply can pass every schema rule and still be wrong — a "return" category attached to a missing-package inquiry — so the guide advises validating on the receiving side and adding human review for uncertain or high-impact cases.

Not sure about something? Ask the AI

Questions and answers are published on this page.

Summaries like this, every morning.

By signing up you agree to the Terms of Service and Privacy Policy.

Context & Analysis

The guide starts from a practical annoyance: if an AI answers a classification request in free text, the program has to interpret phrasing that shifts every time. Fixing the reply to a JSON object with named fields turns that into a lookup — read the field, take the value — but JSON alone is not enough, since a field can be missing or hold a number where a category name belongs. JSON Schema is introduced as the receiving side's contract for what counts as acceptable, and the worked example pins down allowed values with enum, lists both fields in required, and blocks undefined fields with additionalProperties: false. Two easy mistakes: writing a field under properties does not make it mandatory, and extra fields are only rejected if you say so explicitly.

The more important point is the separation of shape from meaning. A reply matching every rule can still carry the wrong category, so the guide lays out a staged path: can it be read as JSON, does it match the schema, is the basis for the classification sound or does a person need to check, and only then does routing happen. It also warns that AI services differ in how much of JSON Schema they accept, and that specifying output on the model side is a different job from validating in the application.

FAQ
Does defining properties in JSON Schema make a field mandatory?
No. Fields listed under properties are not required by themselves; you must also list them in required. To reject undefined fields, you must explicitly set additionalProperties: false.
If an AI reply passes JSON Schema validation, is the classification reliable?
Not necessarily. Schema validation does not guarantee semantic correctness — a reply can satisfy every rule while misclassifying the input. For uncertain classifications or high-impact actions, you need to cross-check against the original input or have a person confirm.
What should the receiving side do if validation fails?
Reading and validating on the receiving side too is recommended, and if that fails, either stopping the automatic processing or sending it back for rechecking.
Send on LINE

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

By signing up you agree to the Terms of Service and Privacy Policy.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.

Questions and answers are published on this page.

Related Articles

Next articleOpenAI closes $11 billion first tranche at $1.25 trillion valuation