Asking for Cards as Structured Output
JSON card schema
Part of: AI Flashcard Generator
You have a list of facts. Now each one has to become a card with a question on the front and an answer on the back. A model does that part, and the most important decision you make is the shape of what you ask it to return. Prose replies are hard to use. If you ask "make a flashcard from this sentence", you get something like "Sure! Q: What does chlorophyll absorb? A: Light." Your code then has to guess where the question starts and where the answer ends, and the next reply will use a different format. That is fragile parsing built on hope. Ask for JSON with a fixed schema. Instead, tell the model exactly which fields you want and ask for JSON only. For this app a card has three fields. - front is a question, ending in a question mark. - back is a short answer, usually a phrase rather than a full sentence. - tags is a list of lowercase topic words, used later to label groups. The prompt states the schema and gives one example. Many providers also accept a JSON schema directly (often called structured output or JSON mode), which makes the model much more likely to return valid JSON. You still validate it yourself in the next lesson, because "much more likely" is not "always". A fake
Challenge: Facts In, Cards Out