hotai.news
← Back to AI WikiAI Wiki / Solve a problem

A requested JSON response includes explanations or wrong fields: how do you validate it reliably?

Valid JSON establishes parseable syntax, not correct fields or business meaning. Distinguish explanatory wrappers, missing fields and wrong types, then check whether the service supports the required schema constraints.

HotAI.news · Sources checked with CodexPublished on 2026-10-20Sources checked on 2026-10-20
Our take

Start troubleshooting here

Valid JSON establishes parseable syntax, not correct fields or business meaning. Distinguish explanatory wrappers, missing fields and wrong types, then check whether the service supports the required schema constraints. Parse and validate after generation finishes, returning explicit failures rather than silently accepting partial results.

01

Separate explanatory text from field-type errors

This applies when an answer adds prose before JSON, omits required fields or returns a number as a string with units. Preserve the raw response and rule out a display layer that removes quotation marks or escaping. An unfinished stream normally lacks closing delimiters, so do not apply final JSON parsing to every intermediate chunk.

02

Check schema requirements and service support directly

Check required fields, types and allowed values in the schema and confirm that the request enables the corresponding output feature. Resolve conflicts between the prompt and schema first, such as requiring null for unknown data in one place but a mandatory number elsewhere. Automatic conversion of a syntactically valid string can hide a wrong business value.

03

Parse and validate after the complete response arrives

Validate the API with a minimal object before adding nested arrays and missing-field cases. Once the complete response arrives, parse it and validate against the same schema. JSON Schema permits additional properties by default; to reject them, set additionalProperties:false and confirm that the service supports it. Return specific errors for bounded retries and preserve the original output for review.

04

Check factual support even after format validation passes

Test normal inputs, absent evidence and invalid numbers, checking both parsing and unknown-value behavior. After format validation, verify amounts and identifiers against the source. Filling every field by inventing missing information still fails; schema compliance is not proof of factual accuracy.

Services support different schema subsets, and complex constraints may need application checks. This page calls no real model API and does not promise that structured output eliminates factual errors. For chat interfaces without enforceable structure, extract and validate the result, but do not delete parsing-error content and pretend the original response passed.

Checked sources

These sources support the concepts and methods described here. Examples and test scope are labeled separately; check the version of the tools you use.

Back to AI Wiki ↗