JSON Schema for AI Feedback: What It Catches and Misses
A JSON Schema is the first gate for AI-classified feedback: it rejects a missing field, a wrong enum, and a number out of range before the data reaches the triage queue. It cannot tell a bug from praise when the label is legal. This article runs 20 synthetic feedback items and 13 edge cases through Python's jsonschema to find the exact boundary — what the schema catches, and what it misses.
The short answer
The schema caught 5 of the 10 edge cases and missed 5. A 3-case follow-up on id uniqueness shows uniqueItems only rejects fully identical objects — two items with the same id but different text still pass, so id uniqueness needs a separate check in code. It catches structure: a missing required field, a value outside the allowed enum, a string where an integer belongs, and a number outside 1–5. It misses everything the schema does not describe: extra fields, duplicate ids, empty text, an empty list, and a bug labeled with a legal enum. The boundary is simple: the schema checks the shape of the data, not the meaning.
The schema and the test data
The schema is feedback-classifier-schema.json, an array of feedback objects. Each object needs an id (string), text (string), type (one of seven enums: bug, feature_request, workflow_gap, pricing_objection, praise, confusion, churn_risk), urgency (integer 1–5), and revenue_impact (high, medium, or low). An optional quote holds the key phrase. The schema file is unchanged for this run.
The test data is 20 synthetic feedback items, each marked synthetic, with a ground-truth label for every field. The mix is 3 bug, 3 feature_request, 3 workflow_gap, 3 pricing_objection, 3 praise, 3 confusion, and 2 churn_risk. These are invented examples, not real customer feedback — no customer data is used, and no model was called. The point is to test the schema, not the model. Two example items show the shape:
All 20 items passed the schema check: 20/20 valid. The edge cases below are where the schema shows its limits.
The script
The check is a short Python script. It loads the schema and the items, validates each item against the item subschema, validates whole lists against the full schema, and prints the result with the exact error message. The script below is the full check used for this run. Save it as feedback-schema-check.py and run it with the schema path as the only argument.
Command and versions for this run:
One detail matters: the schema describes an array, so single items are validated against schema["items"] and whole lists against the full schema. Validating a single item against the full schema fails for the wrong reason — the item is not an array — and hides the real result. The follow-up at the end of the script uses a copy of the schema with uniqueItems: true added — the original schema file is unchanged.
What the schema catches
Five cases, each rejected with an error that names the exact rule that failed:
| Case | What changed | Schema error |
|---|---|---|
| Missing required field | "type" removed | 'type' is a required property |
| Illegal enum | type: "spam" | 'spam' is not one of ['bug', 'feature_request', 'workflow_gap', 'pricing_objection', 'praise', 'confusion', 'churn_risk'] |
| Wrong type | urgency: "3" (string) | '3' is not of type 'integer' |
| Below minimum | urgency: 0 | 0 is less than the minimum of 1 |
| Above maximum | urgency: 6 | 6 is greater than the maximum of 5 |
These five are the schema doing its job. Each error names the exact rule that failed, which makes the failure easy to fix at the source — the model output, or the code that builds the item.
What the schema misses
Five cases, each accepted with no error. Three of them are boundaries the current contract allows: the schema as written permits an extra field, empty text, and an empty list — whether to restrict them is a business decision, not a validator failure. Duplicate id is different — see the follow-up below. And the bug labeled 'praise' is different again — the schema does not judge the label's meaning.
| Case | Why it passes | What closes the gap |
|---|---|---|
| Extra field | The contract does not forbid extra fields | Optional: add "additionalProperties": false only if the business needs strict shapes |
| Duplicate id | No rule requires unique ids | uniqueItems only rejects fully identical objects — see the follow-up; id uniqueness needs a separate check in code |
| Empty text | The contract does not set a minimum length | Optional: add "minLength": 1 on text only if empty feedback is a real problem |
| Empty array | The contract does not set a minimum size | Optional: add "minItems": 1 only if an empty batch is a real problem |
| Bug labeled "praise" | "praise" is a legal enum | The schema does not judge the label's meaning — use a human spot-check or a second pass for the label |
The bug labeled "praise" is the case that matters most. The item is shaped correctly — every field is present, every value is legal — and it is still wrong. The triage queue would route it to the praise pile, and the bug would never be seen. The schema as written does not prevent that, because it never reads the text.
A closer look: uniqueItems does not mean unique ids
uniqueItems compares whole items, not the id field. Run the same pair of items against a copy of the schema with uniqueItems: true added — the original file is unchanged.
| Case | Input | Result | What it shows |
|---|---|---|---|
| Two identical objects | Same id, same text, same everything, twice | Rejected | uniqueItems catches exact duplicates — the error ends with "has non-unique elements" |
| Same id, different text | Same id fb-01, different text and urgency | Accepted | uniqueItems does not check the id field |
| Id-set check in code | Same input as the row above | Catches the duplicate | Duplicate id found: fb-01 |
Id uniqueness is not a schema rule — it is a short check in code: collect the ids, report any that appear twice. The script above ends with that check. The schema can reject exact duplicates; the id set is a business rule, so it belongs outside the schema.
The boundary: structure vs meaning
The schema answers one question: is this data shaped correctly? It does not answer the question that matters for triage: is this label right? A bug labeled "praise" passes every structural rule and fails the only check that counts for the customer — the meaning of the words.
So the schema is a first gate, not the whole check. It belongs at the front of the pipeline: reject malformed output immediately, cheaply, before it reaches a human. Then add a second gate for meaning — a human spot-check of a sample, a second model judging the first, or a rule that flags high-urgency items for review. The schema keeps bad shapes out; the second gate keeps wrong labels out.
How to use this in your own triage
Put the schema check first. Run it on every classified item before it enters the queue — it costs nothing and it catches the malformed output that would otherwise break the downstream code. Then decide, for each of the three optional boundaries — extra fields, empty text, and an empty list — whether the business needs the restriction, and add the rule only if it does. For id uniqueness, add a separate check in code (see the follow-up above), because uniqueItems does not guarantee unique ids. Then add a meaning check for the labels: sample 10% of the items each week and read them, or flag every item where urgency is 4–5 for a human look. The schema and the spot-check together cover what neither covers alone.
Save the schema, the script, and the results where you can search them later. Jizhe keeps copied text, web pages, and images in a local library with Chinese full-text search, so a check run once is two characters away the next time the schema changes.
For the wider triage workflow, see how to build an AI workflow for customer feedback triage. For getting the model to output valid JSON in the first place, see structured output prompting.
Limits and notes
The 20 items are synthetic, invented for this test — they are not real customer feedback, and the results say nothing about real customers. No model was called for this run, so there are no model comparison results here. The schema file is unchanged. The uniqueItems follow-up used a copy of the schema with uniqueItems: true added — the original file is unchanged. Versions matter: the run used Python 3.12.3 and jsonschema 4.10.3; a different jsonschema version may word the errors differently. Re-run the check whenever the schema changes, and re-check the misses — a rule added to the schema changes the boundary.