Turn study notes into an Anki-importable card file
Convert study notes into tab-separated Anki flashcards with one fact per card. Validate column alignment and catch compound answers using a Python script.
When generating flashcards from study notes using AI, relying on markdown tables or comma-separated values (CSV) can misalign columns during Anki import when a comma inside a definition is not wrapped in double quotes (Anki's text import supports quoted fields; see its manual). Furthermore, cramming multiple facts onto the back of a single card inflates review overhead. Structure the prompt to separate questions and answers with a single tab character (\t) and restrict each card to one atomic fact. For table handling principles, see Convert tables to CSV.
[1] Prepare the source study notes. Here is a 1-page summary covering 15 general science concepts.
1. Mitochondria: Cellular organelles responsible for cellular respiration and synthesizing ATP.2. Ribosome: Organelles located in the cytoplasm or endoplasmic reticulum that synthesize proteins.3. Chloroplast: Sites of photosynthesis in plant cells where chlorophyll converts light energy into chemical energy.4. Osmosis: The movement of water molecules across a semipermeable membrane from a region of lower solute concentration to higher solute concentration.5. Enzyme: Protein catalysts that speed up chemical reactions by lowering the activation energy.6. DNA: Double-stranded nucleic acid containing deoxyribose that stores genetic information in living organisms.7. RNA: Single-stranded nucleic acid containing ribose that carries genetic code or transports amino acids during protein synthesis.8. ATP: Direct energy currency for cellular activities consisting of adenosine bound to three phosphate groups.9. Meiosis: Type of cell division in sexually reproducing organisms that reduces the chromosome number by half to produce gametes.10. Homeostasis: Tendency of an organism to regulate its internal environment (body temperature, blood glucose, pH) to maintain stable conditions.11. Insulin: Hormone produced by beta cells in the pancreatic islets that lowers blood glucose levels.12. Plate tectonics: Scientific theory explaining that Earth's outer shell is divided into several plates that glide over the mantle, causing geological activity.13. P-waves: Primary seismic waves that are longitudinal (compressional) and travel through solids, liquids, and gases.14. S-waves: Secondary seismic waves that are transverse (shear) and travel only through solids.15. Electromagnetic induction: Production of an electromotive force across an electrical conductor in a changing magnetic flux.[2] Formulate the prompt. Following Anthropic's prompt engineering recommendations, state formatting constraints explicitly and supply two target examples inside <example> tags. Enforce SuperMemo's Minimum Information Principle to prevent cards from becoming bloated.
You are an expert Anki flashcard creator. Convert the study notes inside <study_notes> into flashcards for Anki import. Strict Rules:1. Output format: TSV (Tab-Separated Values). Each card must occupy exactly one line. Separate the front (question/prompt) and back (answer) with a single tab character (\t).2. One fact per card (Minimum Information Principle): Each card back must contain only ONE atomic fact, term, or short phrase. Do not combine multiple facts with commas, "and", or "as well as". If a concept contains multiple facts, split it into separate cards.3. Clarity and context: The question must provide enough context so the user knows exactly what is being asked without ambiguity, but must not give away the answer.4. Output only the raw TSV lines. Do NOT include markdown code fences, column headers, numbering, or introductory/concluding remarks.5. Cover all 15 concepts from the notes without missing any. <example>What double-stranded nucleic acid stores genetic information in living organisms? DNAWhat 5-carbon sugar is found in the backbone of DNA? Deoxyribose</example> <study_notes>{notes}</study_notes>[3] Run the prompt. Disable external tools with --tools "" and pass the prompt through standard input.
$ claude -p --model claude-sonnet-5-5 --max-turns 1 --tools "" --setting-sources "" --strict-mcp-config < run/anki-en-1.prompt.txt > run/anki-en-1.out.txtThe execution produces 31 card lines. Each concept is broken down into a focused question and answer pair.
What organelle is responsible for cellular respiration in the cell? MitochondriaWhat molecule do mitochondria synthesize as the cell's energy currency? ATPWhat organelle synthesizes proteins in the cytoplasm or on the endoplasmic reticulum? Ribosome…What are the primary seismic waves called? P-wavesWhat type of wave motion do P-waves have? Longitudinal (compressional)P-waves can travel through which states of matter? Solids, liquids, and gasesWhat are the secondary seismic waves called? S-wavesWhat type of wave motion do S-waves have? Transverse (shear)S-waves can travel only through which state of matter? SolidsWhat process produces an electromotive force across a conductor in a changing magnetic flux? Electromagnetic inductionA second run under identical parameters (anki-en-2.out.txt) also produced 31 lines. Comparing both runs showed 8 exact line matches, while the remaining cards differed in more than phrasing: some answers appear in only one run (only in run 1: Amino acids, Mantle, Double-stranded; only in run 2: Adenosine, By half, Electromotive force), so the runs chose and split the facts differently.
[4] Validate the generated cards with a verification script. It checks that every line has exactly two tab-separated columns, that front and back are not empty, that no front is repeated, and that the back has no comma or conjunction (and, as well as) that would suggest several facts in one card. A comma that belongs in the answer (a number, say) is flagged too, and two facts joined without a comma or conjunction are missed.
import re, sys # A comma or a conjunction in the back suggests several facts in one card (a legitimate comma in an answer is flagged too)MULTI = re.compile(r",|\b(?:and|as well as)\b", re.I) lines = open(sys.argv[1], encoding="utf-8").read().splitlines()seen, errors, valid = set(), 0, 0for n, line in enumerate(lines, 1): parts = line.split("\t") if len(parts) != 2: print(f"LINE {n}: [column error] {len(parts)} columns -> {line[:40]!r}"); errors += 1; continue front, back = parts[0].strip(), parts[1].strip() if not front or not back: print(f"LINE {n}: [empty field]"); errors += 1; continue if front in seen: print(f"LINE {n}: [duplicate question] {front!r}"); errors += 1; continue seen.add(front) if MULTI.search(back): print(f"LINE {n}: [possible compound fact] {back!r}"); errors += 1; continue valid += 1print(f"Result: {valid} of {len(lines)} lines pass, {errors} errors")sys.exit(1 if errors else 0)Run it on run 1. There is one error, so the exit code is 1.
$ python run/verify_tsv_en.py run/anki-en-1.out.txtLINE 27: [possible compound fact] 'Solids, liquids, and gases'Result: 30 of 31 lines pass, 1 errorsRun 2 (anki-en-2.out.txt) was flagged at the same line (30 of 31 lines pass).
To test the script itself, anki-bad.en.tsv (6 lines, not model output) mixes a missing tab, an extra column, a repeated front, an empty field and a conjunction. All five defects are caught.
$ python run/verify_tsv_en.py run/anki-bad.en.tsvLINE 1: [column error] 1 columns -> 'What does the ribosome synthesize?,Prote'LINE 2: [column error] 3 columns -> 'What is the organelle where photosynthes'LINE 4: [duplicate question] 'What molecule is the energy currency?'LINE 5: [empty field]LINE 6: [possible compound fact] 'Body temperature and osmotic pressure'Result: 1 of 6 lines pass, 5 errors[5] Address the weak spot. In run 1 and run 2 the same card appears at line 27.
P-waves can travel through which states of matter? Solids, liquids, and gasesDespite the rule against compound answers, the model put all three states of matter on one card back because the source note lists them together. The Korean runs did the same on their P-wave card.
Next, one more run (run/anki-en-3.prompt.txt) with a sixth rule added to Strict Rules:
6. For properties with multiple items (e.g., states of matter, symptoms), create individual true/false or specific identification questions instead of asking for all items in one card.$ claude -p --model claude-sonnet-5-5 --max-turns 1 --tools "" --setting-sources "" --strict-mcp-config < run/anki-en-3.prompt.txt > run/anki-en-3.out.txt$ python run/verify_tsv_en.py run/anki-en-3.out.txtResult: 50 of 50 lines pass, 0 errorsIn that run (50 lines) the P-wave question became three true/false cards, and the check passed:
True or false: P-waves can travel through solids. TrueTrue or false: P-waves can travel through liquids. TrueTrue or false: P-waves can travel through gases. TrueThe same rule added to the Korean prompt, in one Korean run, left the P-wave card as it was (run/anki-ko-3.out.txt, 52 lines). One run each is too little to call the rule dependable; check list-type cards by hand and fix what remains.
[6] Import into Anki. In the Anki desktop application, select File → Import (shortcut Ctrl+I) and choose the generated TSV file.
- Field separator: Select
Tab - Field mapping: Assign Field 1 to
Frontand Field 2 toBack - Existing notes: Set the duplicate handling option to
Preserve existing notes.