The Extraction Prompt: Ask for JSON
structured extraction into a JSON array
Part of: Flashcard Maker
One card per call is fine for a demo, but real notes hold many facts per chunk. You want the model to read a chunk and hand back several cards at once, in a shape your code can loop over. The tool for that is structured extraction : instruct the model to return a JSON array of card objects. Why JSON instead of the Q:/A: format The Q:/A: layout worked for exactly one card. For many cards you'd invent separators and count blank lines, brittle. JSON is the standard, well-defined format for a list of objects, and Python's json module parses it in one line. When you want many structured items back from a model, you ask for JSON. The extraction prompt The system prompt has real work to do here. It names the task, pins the exact schema, and sets rules that keep garbage out: A few details carry the reliability here. "Return ONLY a JSON array" discourages the chatty "Sure! Here are your cards:" preamble that breaks parsing. The exact keys (question, answer) mean your loop can rely on them. The example shows the shape better than any description can. One line of sample output is worth a paragraph of rules. The call That json.loads is why you asked for JSON in the first place. The text become
Challenge: Cards Per Note