Validating and Repairing Model Output

schema validation

Part of: AI Flashcard Generator

Asking for JSON is half the job. The other half is checking what actually came back, because a model will eventually send you a reply that breaks the contract. If that reply goes straight into the deck, the learner sees a blank card or the app crashes on render. Three outcomes for every reply. Every raw reply ends up in one of three buckets. - Accept it as is, because it parses and every field has the right type. - Repair it, because it is close enough that a small, safe fix makes it valid. - Reject it with a reason you can log, because guessing would put wrong data in front of a learner. The line between repair and reject matters. Adding a missing question mark to the front is safe. Inventing an answer for a card that has no back is not. The checks, in order. The order is deliberate. You check that the text parses before you look inside it, and that it is an object before you call .get on it. Each failure returns a short reason string instead of raising, so one bad card never stops the batch. Duplicates. Models repeat themselves, especially when two source sentences say the same thing in different words. After validation, drop any card whose front matches an earlier one, ignoring

Challenge: The Validation Desk