AI MOOC
✦ Grow togetherInvite 3 friends, earn 1 month of membership · Up to 12 monthsInvite friends →
← All editions
Daily AI

How to check AI-generated JSON: three counterexamples

Use a fictional reimbursement rule to separate JSON parsing, field validation, and factual review.

Define the output contract

Practice source: fictional rule P1 says “The lodging cap for full-time employees is 400 yuan per night”; it states no cap for interns. Ask the AI to answer only from the source and return a JSON object: answer is a non-empty string, citations is an array of strings, and abstain is a boolean. If evidence is insufficient, abstain should be true and answer should name the gap. Allow only source IDs actually supplied in this request. Do not send real reimbursement data to an unapproved tool.

Move from syntax to fields

First parse the complete response as JSON; if parsing fails, retain the error and stop. Parsing alone does not validate fields. Example one: {“answer”:“unknown”} uses curly quotes and is not valid JSON. Example two: {"answer":"unknown","citations":[],"abstain":"true"} parses, but abstain is a string rather than a boolean and must be rejected. On the server, also check the top-level object, required fields, a non-empty answer, array element types, and the policy for extra fields.

Then review citations and meaning

Example three: {"answer":"Interns are capped at 400 yuan per night","citations":["P1"],"abstain":false} has the requested types and P1 was supplied, but it applies the full-time employee rule to interns. Mark it factually wrong. Compare the audience, conditions, units and numbers against the source. Structural validation and an ID allowlist cannot prove a citation supports the claim. A human reference should state that the intern cap is unspecified and set abstain to true rather than inventing a cap.

Turn the exercise into a workflow

Use the three hand-written examples to test parsing, type validation and human factual review separately. Also test missing fields, unknown citations and oversized input, recording actual results. Limit response size and retries; on validation failure, do not save critical business data or automatically pay or send messages. JSON Schema can express field and required-property rules, but truth still needs independent review. Do not present teaching examples as observed model results if no model was called.

Reference:JSON Schema: object properties and required fields

Continue: assemble and cite RAG evidence (free) →