AI Test Maker: 60 of 120 Formula Items Break GIFT Import
The quiz looks right in the chat window and wrong in the course: a question with two correct answers, or an empty stem, appearing only after import.
📜 Table of Contents
📖 Keep reading
Ask a model for twenty multiple-choice questions from three passages that carry formulas. Run the 120 items through the import path Moodle's GIFT format uses. Sixty of them never reach a student in the shape they were written: 34 are rejected outright because a brace ends the answer block before it starts, 23 arrive with more than four options and several of them marked correct, and 3 with options missing or the wrong one marked. Escape six control characters before writing the file and all 120 come through intact, word for word.
The arithmetic was never the problem. A second model, given only the stems and options with no key, solved all 120 and agreed with the generated key every time. What breaks is the handover to the software that will serve the quiz.
What was measured
- Three passages I wrote for this test, each 110 to 170 words with its own numbers: a resistor circuit (V = IR, P = I^2 R, series and parallel), an ideal gas sample (PV = nRT, the two-state law, density), and a savings account (simple interest, compound interest, effective annual rate).
- Twenty multiple-choice items per passage, four options, one key, from deepseek-flash at temperature 0.5, in six calls on 2026-11-26.
- Two prompts. A: "write 20 multiple-choice questions from the passage, four options, one correct answer". B: the same, plus "write every formula, symbol and quantity with units in LaTeX inside backslash-parenthesis delimiters" and "every numeric answer must carry its unit".
- Every inline formula segment rendered with matplotlib's mathtext parser. That is a syntax check by a TeX renderer, not a test of MathJax in a browser.
- Each item written as one GIFT question and read back by a replication of Moodle's importer: question/format/gift/format.php from MOODLE_405_STABLE, the brace search, the equal-sign substitution and the tilde split. I did not run a live Moodle instance; the code path is the documentation of record here.
- The same 120 items written in Aiken format and read back by a parser matching its published rules: stem, four option lines, ANSWER: letter, blank line between items.
- A blind re-solve: deepseek-chat at temperature 0, given the stem and the four options, no key, no passage, ten items per call, twelve calls.
Two prompts, two notations
The plain prompt leaves the notation decision to the model, and the model does not make it once. Out of 60 items, 39 carry something mathematical, 18 write exponents with a caret, 9 use unicode superscripts and multiplication signs, and 3 put both inside one quiz. Nothing is in LaTeX.
| prompt | items carrying math | caret notation | unicode symbols | two notations in one quiz | inline LaTeX |
|---|---|---|---|---|---|
| plain | 39 of 60 | 18 | 9 | 3 | 0 |
| LaTeX asked for | 60 of 60 | 0 | 0 | 0 | 402 segments |
The second prompt removed all of that: 402 inline segments, every one inside the requested delimiters, no dollar signs, no unicode superscripts, no quiz mixing two styles. All 402 parsed without an error. On notation alone, the instruction works exactly as advertised.
The answer keys hold up
Before blaming the format, check whether the items are worth importing. A second model solved all 120 from the stems and options alone, blind to the key and to the passage. It matched the generated key 120 times out of 120. That is agreement between two models of the same family, not proof of correctness, and the items are short arithmetic with the numbers given. It does rule out the failure being wrong answers: the item content is fine, and the loss happens downstream.
How GIFT reads a question
Moodle's importer does four things that matter here, all of them visible in format.php. It finds the answer block with the first brace in the text and ends it at the first closing brace, not the last. It replaces every equal sign in that block with a tilde and an equal sign. It splits on tildes, so a tilde that was inside an option becomes a new option. And an option that now starts with an equal sign counts as correct, so a stray equal sign manufactures a second key.
The escape hatch is the backslash: the six characters colon, hash, equals, open brace, close brace and tilde lose their meaning when preceded by one, and the importer swaps them for placeholders before it does any of the above. LaTeX uses two of those six as its own syntax, which is the whole collision.
Sixty of 120 arrive broken
| what the importer ends up with | A, as written | A, escaped | B, as written | B, escaped |
|---|---|---|---|---|
| 4 answers, 1 correct | 47 | 60 | 13 | 60 |
| more than 4 answers | 13 | 0 | 10 | 0 |
| fewer than 2 answers, item rejected | 0 | 0 | 34 | 0 |
| 2 or 3 answers, or the wrong one marked | 0 | 0 | 3 | 0 |
Arm A breaks on the equal sign. Thirteen of its 60 items have a formula in the options, and an option written "I = V / R" gives the importer two more answer markers. Those items import as multi-answer questions with seven or eight options and four or five of them marked correct.
Arm B breaks harder, which is the counter-intuitive part. Asking for LaTeX means every unit arrives as a command with a brace, and the first brace in the text is now inside the question stem instead of at the start of the answer block. Thirty-four items are cut off before their first option and rejected for having fewer than two answers. Ten keep their extra answers from equal signs, and three end up with two or three options or with the wrong option marked. Only thirteen of the sixty survive untouched.
Arm A looks safer for exactly the wrong reason: its formulas are plain text, so escaping is a formality and nothing else in the item is special. It is still 13 of 60, and a teacher who exports 40 items a week meets that several times a month, usually as a question that quietly has two right answers.
Escaping puts all 120 back
Run the same 120 items through a twelve-line function that puts a backslash in front of the six control characters, skipping any character that already has one so TeX commands survive, and the importer sees four answers and one key for every item: 120 of 120. The recovery check is stricter than "it imported" — the four options come back in the original order, character for character, with the right one marked, 120 of 120.
SPECIAL = ": #={}~".replace(" ", "")
def gift_escape(text):
out, i = [], 0
while i < len(text):
if text[i] == chr(92) and i + 1 < len(text):
out.append(text[i:i + 2]) # leave existing TeX commands alone
i += 2
continue
out.append(chr(92) + text[i] if text[i] in SPECIAL else text[i])
i += 1
return "".join(out)
stem = gift_escape(item["question"])
opts = [gift_escape(o) for o in item["options"]]
body = " ".join(("=" if k == key else "~") + o for k, o in enumerate(opts))
Two details worth keeping. Escape the question stem as well as the options: a LaTeX command in the stem is what cut off 34 items, and that failure does not look like a formatting problem when you see it, it looks like an empty question. And escape only what needs it; a blanket replacement of backslashes turns every math command into literal text.
Aiken does not have this failure
The same 120 items in Aiken format break zero times: a stem line, four option lines, ANSWER: B, a blank line. There are no control characters in the answer section, so no formula can collide with the syntax. The price is real: four options only, no per-option feedback, no partial credit, no matching or numeric types. For a formula-heavy set that a teacher will import once and hand out, that is often the better trade than debugging GIFT.
Three things to take
One, ask for LaTeX explicitly and ask for units in the key; the measured difference is 18 caret-written items and 9 unicode items dropping to zero, at the cost of 402 segments that all render.
Two, escape before you write the file, not after the import looks wrong. The check is one line: count unescaped equals signs and braces in the answer block of each item, and refuse to write the file if the count is not exactly one equal sign per item plus whatever the stem legitimately needs escaped.
Three, if the course has no math renderer enabled, the LaTeX is shown raw to students. The format fixes the import; it does not fix the display.
What this does not show
One model family, three passages I wrote, one run per arm. The importer numbers come from a faithful replication of Moodle's code, not from a live site, so the exact counts could shift by an item or two on a specific Moodle version; the mechanism, a stray equal sign or brace becoming syntax, will not. No student sat these items. The blind re-solve shares a family with the generator, so 120 of 120 is weaker evidence than it looks. Aiken's zero is a property of the format, not a quality claim about the items.
Three numbers to carry: 60 of 120 items arrive at the importer in the wrong shape; 34 of 60 LaTeX items are rejected outright because a brace in the stem ends the answer block; 120 of 120 come through once the six control characters are escaped. For what those items are worth once they land, the nine free tools compared on the answer-key question are in the free quiz maker breakdown; the sibling failure, 17 of 90 cloze keys accepting a second wording, is in the cloze run; the six checks that catch unusable items before import are in the six-check gate; and the table-sourced items, 60 copied cells and 18 unit mix-ups, are in the table run.
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.