AI JSON Outputs: Check Syntax, Schema, and Values
An AI response in JSON may look ready for software to use, yet missing fields or incorrect numbers can still cause errors. Check the response’s syntax, schema, and values separately before passing it into a system.

Check both the JSON format and the data extracted by AI
When AI reads emails, quotations, or requests and returns JSON for system import, errors occur at at least three levels: unparseable JSON, parseable JSON with incorrect fields or types, and structurally valid JSON whose values differ from the source document such as entering the wrong amount or inventing a date. Checking only whether JSON parses is insufficient.
A practical approach is to define a schema in advance, validate against it, and recheck important values against the original. The documentation OpenAI Structured Outputs clearly distinguishes JSON mode, which mainly guarantees JSON format, from Structured Outputs, which targets a supported JSON Schema. Documentation also notes structured answers can still be factually wrong.
Check AI-generated JSON for syntax, structure, and factual accuracy
| Review layer | Question | Examples that have not yet been passed |
|---|---|---|
| Syntax | Can a JSON parser open it? | An unclosed quotation mark or an extra comma |
| Schema | Does it meet the agreed fields and data types? | amount is text when a number is required |
| Meaning | Do the values extracted match the evidence and business rules? | The amount in the document is 1,250 baht, but the AI sent 12,500 |
JSON Schema uses keywords like type and required to define data types and required fields, following the guide JSON Schema However, a schema cannot independently prove that an entered number matches the receipt
Hypothetical example: Read one payment transaction.
Suppose the source says “On October 12, 2026, purchased office equipment for 1,250 baht, excluding VAT.” We want AI to extract the date, item, amount, and tax status for human review, not calculate unspecified tax.
{
"date_text": "12 ต.ค. 2569",
"item": "อุปกรณ์สำนักงาน",
"amount_thb": 1250,
"vat_status": "not_included",
"vat_amount_thb": null
}
This example is Hypothetical data not actual model-call results. Using null means the source has not yet provided a tax amount. Do not enter 0, which could imply confirmed zero tax. Setting the status not_included must be a term agreed by the team, not a universal JSON convention.
The schema below requires amount_thb as a number or null, item as a string or null, and vat_amount_thb as number or null, enforcing all required fields. Convert Buddhist years to Gregorian using explicit, verifiable rules rather than letting the model guess.
Example JSON Schema for the above hypothetical data. (This is a sample structure, not a ready-to-run API request):
{
"type": "object",
"properties": {
"date_text": { "type": ["string", "null"] },
"item": { "type": ["string", "null"] },
"amount_thb": { "type": ["number", "null"] },
"vat_status": { "type": "string", "enum": ["not_included", "included", "unknown"] },
"vat_amount_thb": { "type": ["number", "null"] }
},
"required": ["date_text", "item", "amount_thb", "vat_status", "vat_amount_thb"],
"additionalProperties": false
}
required requires the field name, but does not prohibit null if the data type allows it, while additionalProperties: false Disallow fields outside the contract, following JSON Schema object guide This example uses unknown when tax status is unknown, and allow a blank amount when evidence is absent. If a transaction requires an actual amount, add rules rejecting unknown values.
For OpenAI, you must also enable Structured Outputs in the format required by the API you use. Writing a schema in the prompt alone does not enable this mode. The documentation requires every field to be in required and objects use additionalProperties: false with only a subset of schema support. This example specifies no model and makes no API call, and does not certify replacement of application-side validation.
Steps for checking AI output before passing it to a system
- Define fields before sending documents: Specify field names, types, accepted values, and the meaning of blanks, such as
nullThat is, no information was found. - Send only necessary data: Remove unnecessary personal or confidential data before using external services, and review providers' retention policies
- Request structured results: If the API supports Structured Outputs, use the actual supported schema. It is not assumed that all models or versions are equally supported.
- Check the syntax and schema on the program side: Handle cases of incomplete or rejected answers. Not all responses are considered valid JSON.
- Check the values with the document: especially amounts, reference numbers, dates, and names. Retain evidence locations or text for human review where appropriate.
- Test edge cases: For example, missing dates, two amounts, or inconsistent currencies, before production use
To measure quality, prepare samples with reviewed reference answers. Measure schema validity and correct value extraction separately. A 100% schema pass rate does not imply 100% factual accuracy.
Schema limits and when to stop before saving
- Schema is too strict: may force the model to select a value unsupported by the document if no “Unknown” status or
null - Wrong answer but looks systematic: Well-formatted JSON can still contain information absent from the source.
- Support is not the same: Providers and model versions support only subsets of JSON Schema. Check documentation for the version actually used.
- Refusal or missing message: The program must handle these cases without automatically storing incorrect values.
For tasks affecting money, permissions, or personal data, require human acceptance or independent rules before executing transactions. Passing JSON Schema validation does not constitute transaction approval.
Make the data readable by the system and enable people to check the truth
Before connecting AI to a system, define which fields are required, which may be unknown, who checks the numbers, and what happens when validation fails. These decisions make the process easier to audit than simply asking the model to return JSON.
Sources
Based on original documentation checked on October 14, 2026. JSON examples are hypothetical, not actual model or API test results. Check version documentation and provider data policies before use.