Keeping Only Good Cards

validating and repairing the deck

Part of: Flashcard Maker

Even with clean JSON and no duplicates, the model occasionally hands you a card that shouldn't exist: an empty answer, a "question" that's actually a statement, or a card where the question and answer are the same string. Studying junk cards trains bad habits, so the last gate before export is a validator that drops anything not worth memorizing. What makes a card bad A few failure modes cover almost all of it: - Empty fields. A missing or blank question or answer, useless. - Question equals answer. {"question": "Photosynthesis", "answer": "Photosynthesis"} teaches nothing. - Runaway length. A "card" that's a whole paragraph is the model dumping the note instead of extracting a fact. Cap the length. - Wrong type. A stray number or null where a string should be, guard against it so a bad element can't crash the run. The validator Encode those rules as one predicate and filter the deck through it: Notice the order: cheapest, most-likely checks first (type, emptiness), then the subtler ones. Each rule is one line, and together they turn "the model probably behaved" into a guarantee your export step can trust. Report, don't hide Print how many cards you dropped. A run that quietly disc

Challenge: Keep Valid Cards