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
The receipt says 1,250 baht, but the AI returns 12,500 in its JSON. The program can parse it, every field is present, and the value is a number. Save it immediately and the record is still wrong. Check the JSON syntax, its structure, and the values against the document.
First agree on the values each field may hold, then validate the response in your application. OpenAI’s documentation on OpenAI Structured Outputs explains that JSON mode focuses on producing parseable JSON, while Structured Outputs aims to match a supported JSON Schema. A valid structure does not establish that the extracted facts are right.
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 |
If the field amount is a string instead of a number, use type to check the data type, and required to check that all required fields are present, as described in the JSON Schema guide. Even when both checks pass, compare the amount with the receipt yourself.
Hypothetical example: Read one payment transaction.
Take this hypothetical source: ‘วันที่ 12 ต.ค. 2569 ซื้ออุปกรณ์สำนักงาน 1,250 บาท ยังไม่รวม VAT’. The AI should extract the date as written, the item, amount, and VAT status for a person to review. It should not supply a VAT amount the source does not give.
{
"date_text": "12 ต.ค. 2569",
"item": "อุปกรณ์สำนักงาน",
"amount_thb": 1250,
"vat_status": "not_included",
"vat_amount_thb": null
}
The figures and wording here are Hypothetical data not an API result. The value null means the document does not state the VAT amount. A zero could imply someone checked and found no VAT. The code not_included is defined by your team, not by the JSON standard.
If the document omits an amount, amount_thb as well as vat_amount_thb may be null rather than a number; item may likewise be null rather than a string, even though every field name is required. The example uses a Buddhist Era date. If your system needs the Common Era, use a verifiable conversion rule 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
}
Having every field listed in required still allows null if the declared type permits it. Meanwhile, additionalProperties: false disallows extra fields. See the JSON Schema object guide Use unknown for an unknown VAT status under this contract, and leave the amount unset without evidence. A system that requires an amount must reject or hold the record itself.
Putting this schema in a prompt does not enable Structured Outputs. With OpenAI, configure the mode for the API you use and check which schema features the model supports. Its documentation requires every field in required and each object to set additionalProperties: false This example neither calls an API nor specifies a model; it does not replace validation in your application.
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
Keep sample documents and human-checked answers as a test set. Measure schema compliance separately from amounts and dates matching the source. Even 100% schema compliance does not mean 100% extraction accuracy. Hold records with incorrect amounts for review instead of saving them automatically.
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 transactions affecting money, rights, or personal data, use a person or independent rule to review the result before acting. A JSON Schema pass establishes only that the data fits the expected format; it is not transaction approval.
Make the data readable by the system and enable people to check the truth
Before writing to the database, decide who checks the source when an amount disagrees and where that record waits. Define how unknown values and rejected records are handled alongside the schema. Only then can you tell which results may enter the system.
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.