JSON Schema · AI Feedback

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.

FreeAudience: Developers & AI teams

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:

{"id": "fb-01", "text": "Every time I export a draft to PDF, the tables come out blank.", "type": "bug", "urgency": 4, "revenue_impact": "high", "quote": "the tables come out blank"} {"id": "fb-05", "text": "The new outline mode is excellent. The team actually likes using it.", "type": "praise", "urgency": 1, "revenue_impact": "low", "quote": "The team actually likes using it"}

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.

import copy import json import sys import jsonschema # One example item (fb-01), a bug report. The full run used 20 such items. ITEM = { "id": "fb-01", "text": "Every time I export a draft to PDF, the tables come out blank.", "type": "bug", "urgency": 4, "revenue_impact": "high", "quote": "the tables come out blank", } CASES = [ ("missing required field 'type'", lambda it: it.pop("type")), ("illegal type enum value 'spam'", lambda it: it.update({"type": "spam"})), ("urgency as string '3'", lambda it: it.update({"urgency": "3"})), ("urgency out of range (0)", lambda it: it.update({"urgency": 0})), ("urgency out of range (6)", lambda it: it.update({"urgency": 6})), ("extra field 'priority'", lambda it: it.update({"priority": "high"})), ("empty text ''", lambda it: it.update({"text": ""})), ("bug text labeled as legal enum 'praise'", lambda it: it.update({"type": "praise"})), ] schema = json.load(open(sys.argv[1])) item_v = jsonschema.Draft7Validator(schema["items"]) list_v = jsonschema.Draft7Validator(schema) for name, mutate in CASES: bad = copy.deepcopy(ITEM) mutate(bad) errs = list(item_v.iter_errors(bad)) print(name, "->", "REJECTED" if errs else "accepted", [e.message for e in errs]) # Array-level cases: duplicate id, empty array. print("duplicate id ->", "REJECTED" if list(list_v.iter_errors([ITEM, ITEM])) else "accepted") print("empty array ->", "REJECTED" if list(list_v.iter_errors([])) else "accepted") # Follow-up: uniqueItems compares whole items, not the id field. # SAME_ID has the same id as ITEM but different text, urgency, and quote. SAME_ID = dict(ITEM, text="Search doesn't find anything when I type in Chinese.", urgency=3, revenue_impact="medium", quote="Search doesn't find anything when I type in Chinese") schema_u = copy.deepcopy(schema) schema_u["uniqueItems"] = True list_u = jsonschema.Draft7Validator(schema_u) errs = list(list_u.iter_errors([copy.deepcopy(ITEM), copy.deepcopy(ITEM)])) print("uniqueItems, two identical objects ->", "REJECTED" if errs else "accepted", [e.message for e in errs]) errs = list(list_u.iter_errors([ITEM, SAME_ID])) print("uniqueItems, same id different text ->", "REJECTED" if errs else "accepted", [e.message for e in errs]) # Id uniqueness is a business rule: check it in code, not in the schema. seen, dupes = set(), [] for it in [ITEM, SAME_ID]: if it["id"] in seen: dupes.append(it["id"]) seen.add(it["id"]) print("id-set check, same id different text -> duplicate ids found:", dupes or "none")

Command and versions for this run:

python3 feedback-schema-check.py web/assets/downloads/feedback-classifier-schema.json Python 3.12.3 · jsonschema 4.10.3

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:

CaseWhat changedSchema error
Missing required field"type" removed'type' is a required property
Illegal enumtype: "spam"'spam' is not one of ['bug', 'feature_request', 'workflow_gap', 'pricing_objection', 'praise', 'confusion', 'churn_risk']
Wrong typeurgency: "3" (string)'3' is not of type 'integer'
Below minimumurgency: 00 is less than the minimum of 1
Above maximumurgency: 66 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.

CaseWhy it passesWhat closes the gap
Extra fieldThe contract does not forbid extra fieldsOptional: add "additionalProperties": false only if the business needs strict shapes
Duplicate idNo rule requires unique idsuniqueItems only rejects fully identical objects — see the follow-up; id uniqueness needs a separate check in code
Empty textThe contract does not set a minimum lengthOptional: add "minLength": 1 on text only if empty feedback is a real problem
Empty arrayThe contract does not set a minimum sizeOptional: add "minItems": 1 only if an empty batch is a real problem
Bug labeled "praise""praise" is a legal enumThe 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.

CaseInputResultWhat it shows
Two identical objectsSame id, same text, same everything, twiceRejecteduniqueItems catches exact duplicates — the error ends with "has non-unique elements"
Same id, different textSame id fb-01, different text and urgencyAccepteduniqueItems does not check the id field
Id-set check in codeSame input as the row aboveCatches the duplicateDuplicate 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.

Related reading