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.

Documents pass through three review layers before becoming organized data

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 layerQuestionExamples that have not yet been passed
SyntaxCan a JSON parser open it?An unclosed quotation mark or an extra comma
SchemaDoes it meet the agreed fields and data types?amount is text when a number is required
MeaningDo 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

  1. Define fields before sending documents: Specify field names, types, accepted values, and the meaning of blanks, such as null That is, no information was found.
  2. Send only necessary data: Remove unnecessary personal or confidential data before using external services, and review providers' retention policies
  3. 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.
  4. Check the syntax and schema on the program side: Handle cases of incomplete or rejected answers. Not all responses are considered valid JSON.
  5. Check the values with the document: especially amounts, reference numbers, dates, and names. Retain evidence locations or text for human review where appropriate.
  6. 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

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.

Try the toolFormat JSON and check syntaxCheck JSON parsing and format it for readability. This tool does not validate schemas or accuracy against source documents.

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.