Strict Output
You'll make a model return machine-readable JSON a hundred times in a row, validate every reply, and bring the failure rate down with the right tools.
About
The moment you build anything on a model, you need its answers in a shape a program can read, and models are bad at shapes. Asked nicely for JSON, a small model adds a friendly sentence, a trailing comma or a field you never asked for, and your program falls over on reply number 37. This weekend is the loop every builder learns: ask for a structure, check it with a real parser, count failures, and fix them with a schema, a grammar or a retry. A hundred runs is enough to see a 3 percent failure rate, which is the kind that hides in testing and bites in use.
At a glance
- Per requirement
- 25 XP
- Completion bonus
- 150 XP
- Requirements
- 5
- Takes
- One weekend
- Skill level
- Intermediate (months of practice)
- Cost
- Free
- Supplies
- Nothing special
- Where
- At home
- Other people
- On your own
Requirements
-
1
Define a schema with five fields for a real extraction task. Something like pulling a date, an amount, a merchant, a category and a confidence score out of a pasted receipt or email. Write the schema as JSON with types. Take a screenshot of the schema. Photo
-
2
Ask for JSON plainly and run a hundred inputs through a script. Collect or make a hundred inputs, including a few messy ones with no amount or two dates. A bigger model can draft most of them, and twenty real ones mixed in keep it honest. Send each to the model with the schema in the prompt. Save every raw reply. Take a screenshot of the script running with the count. Photo
-
3
Validate every reply with a parser and count the failures. Parse each reply with your language's JSON library and then check types and required fields. Count the kinds of failure separately: not JSON at all, extra text around it, missing field, wrong type. Take a photo of the tally with a percentage. Photo
-
4
Fix it with structured output, a grammar or a retry loop, and rerun. Most runners support a JSON mode or a grammar that forces valid output, and a retry that resends the error message is a fair fallback. Rerun the hundred. Take a screenshot of the new failure count next to the old one. Photo
-
5
Find the inputs that are still wrong even when the JSON is valid. A reply can be valid JSON and still wrong. Check twenty replies by hand against the input and count how many have the right values. Take a photo of your check sheet, and write one line on which field the model most often gets wrong. Photo