You ask an AI assistant to turn a fictional attendance note into structured text. The note says, “Python workshop: three people attended.” The assistant returns this response:
{"session": "Python", "attendees": "three"}
The punctuation is correct. A JSON parser can read it. Yet a report that expects a numeric attendance count cannot safely use it as-is. This small example reveals three separate checks: can we read the response, does it follow our agreed structure, and does it match the original note?
You can read this example without running code. It helps to know that JSON stores named fields such as session and attendees; the examples below show their values directly.
This is a text-only extraction exercise. It does not make bookings, send messages, or change anything in another application.
Give each check a job
Parsing checks whether text can be interpreted as JSON. It does not establish that the result contains the fields your application needs. Python's JSON decoder turns JSON into Python values; decoding an object typically produces a dictionary. Python JSON documentation
A schema describes expected structure. For our fictional workshop, we want a session name and an attendance count between one and six, the range allowed in this small-group example. A JSON Schema could be:
{
"type": "object",
"properties": {
"session": {"type": "string", "minLength": 1},
"attendees": {"type": "integer", "minimum": 1, "maximum": 6}
},
"required": ["session", "attendees"],
"additionalProperties": false
}
The properties section describes known fields. Required makes both fields mandatory. Disallowing additional properties rejects unexpected keys rather than silently accepting them. Those are separate choices: listing a property does not by itself make it mandatory. JSON Schema object reference
The numeric rules reject the string “three,” zero, seven, and fractional counts such as 2.5. The integer rule concerns the numeric value: JSON Schema can accept 3.0 as an integer value. It does not require a particular printed spelling. JSON Schema numeric reference
Walk through four responses
Consider these possible outputs:
{"session": "Python", "attendees": 3}
{"session": "Python", "attendees": 0}
{"session": "Python", "attendees": 3, "colour": "blue"}
{"session": "Python", "attendees": 5}
The first follows the schema and matches the note. The second violates the minimum. The third introduces an unexpected field. The fourth is the interesting one: it passes the schema but contradicts the recorded attendance.
This is why a green validation result is not a truth certificate. A structural check can confirm that five is an allowed number, but not that five people attended. You still need to compare the response with the original note.
Display the extracted session, attendance count, and original sentence together. If the values disagree, mark the result for review. Here the source supports changing five to three. If the source were unclear, do not invent a number just to make the report complete.
Make failure visible
Imagine the program only prints “Something went wrong.” The learner cannot tell whether the response was unreadable, incomplete, or inconsistent with the note. Prefer specific categories such as invalid JSON, missing attendance count, out-of-range quantity, and source mismatch. Avoid putting sensitive original text into public error messages or logs.
A retry can ask for a corrected representation, but it should be bounded. Repeatedly asking until something passes can hide a persistent problem. Keep a record of which check failed, and route uncertain cases to a person rather than manufacturing a confident value.
Try it yourself
A source note says, “SQL workshop: two people attended.” Which checks should reject these responses?
{"session": "SQL"}{"session": "SQL", "attendees": 2}{"session": "Python", "attendees": 2}
The first fails the required-field rule. The second passes structure and agrees with this source. The third passes structure but fails the source comparison. The check is about faithfully representing the note, not investigating whether the note itself is accurate.
When you connect AI output to software, keep these questions separate. Readable data, the expected structure, and agreement with the source are different checks.