Skip to content

Fix MCQ letter extraction for chat-style ANSWER lines - #433

Merged
gregorybchris merged 6 commits into
mainfrom
chrisg/fix-mcq-letter-extraction
Oct 2, 2026
Merged

gregorybchris merged 6 commits into
mainfrom
chrisg/fix-mcq-letter-extraction

Conversation

@gregorybchris

@gregorybchris gregorybchris commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The shared ANSWER: X regex misread two common chat-model output styles:

Output Before After
ANSWER: the correct choice is C T no match from this pattern; falls through to the later patterns
**Answer:** B None B
Answer: **(C)** C C
Answer: _B_ None B
**Answer:**\n\nC None C
Answer C, **Answer** (B) None C, B
Let me answer a) first.\n\boxed{C} C C

Cause: the pattern used re.IGNORECASE, so [A-Z] also matched the lowercase first letter of the next word. It also did not allow ** between the colon and the letter.

Fix: a single ANSWER_LINE_PATTERN in evals/extract/mcq.py. It requires the letter to stand alone ((?!\w)), allows *, _ and ( around the label and the letter. The letter may also start the next non-blank line (**Answer:**\n\nC), but only when it stands alone there or labels an option (B), (B) Paris). That keeps Answer:\n\nA good approach… from capturing A. GPQA and LabBench already matched a next-line letter on main; BBQ, WMDP and MedQA now do too. The guard rejects a following letter or digit, so a trailing _ of emphasis is accepted. Lowercase single letters (answer: c) still match, as before.

The colon is optional (Answer C). Without it, the letter must be on the same line, uppercase, and stand alone or label an option. That keeps prose such as answer a) first or answer A good question from matching. The guard matters because the ANSWER pattern outranks \boxed{}, so an early false match would beat the final answer. One known false match remains: prose that names an uppercase option, such as I'd answer (A) at first, but … \boxed{C}, returns A.

Affected tasks

  • BBQ, WMDP, MedQA use extract_mcq_answer directly.
  • GPQA and LabBench had their own copies of the regex. They now import the shared pattern and keep their own fallbacks. In GPQA, ANSWER: the correct choice is C now reaches the last-capital-letter fallback and returns C. LabBench has no fallback, so it returns None.

Results already stored for these tasks may be affected. They are not re-scored in this PR.

Testing

  • New cases in tests/evals/extract/test_mcq.py, tests/evals/tasks/test_gpqa.py and tests/evals/tasks/test_lab_bench.py. The positive cases fail on main and pass with this change. The false-match cases pass on both and guard against new false matches.
  • uv run pytest tests/ --ignore=tests/integration: 2896 passed, 34 skipped.
  • ruff check and ruff format --check are clean. ty check reports one warning, an unused type: ignore in harness/sandbox/executor.py. That warning is also on main.

🤖 Generated with Claude Code

The ANSWER: pattern was case-insensitive, so its [A-Z] matched the first
letter of any word ("ANSWER: the correct choice is C" extracted T). It
also rejected markdown around the label ("**Answer:** B" extracted
nothing). The letter must now stand alone, and emphasis or parentheses
around the label and letter are allowed.

GPQA and LabBench now share this pattern with the native MCQ extractor
instead of carrying their own copies.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@gregorybchris
gregorybchris requested a review from a team as a code owner October 1, 2026 18:09
gregorybchris and others added 3 commits October 1, 2026 13:14
The pattern allowed a leading underscore but rejected a trailing one,
since (?!\w) treats underscore as a word character. Also pin that GPQA and
LabBench no longer match a letter on the line after ANSWER:.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Chat models often put the letter on its own line ("**Answer:**\n\nC").
GPQA and LabBench matched this on main, and LabBench, which has no
fallback, returned None after the shared pattern went same-line only. The
next-line letter must stand alone or label an option, so a sentence that
starts with "A" or "I" is not read as an answer.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@mgmorgan23

Copy link
Copy Markdown
Contributor

Three (very flexible) flags:

  • Maybe make the : in the pattern optional (ie, match "Answer C"). The downside of this is I think it would raise the possibility of false matches, though taking the last one should help mitigate that
  • I think we don't match plain {} brackets anywhere ("Answer: {C}" or "Answer: \boxed{C}"). I don't know how common of a pattern that ends up being?
  • I think the base extract function never picks up on "ANSWER: the correct choice is C" -- gpqa has a last ditch "single capital letter" catch but the others don't. This would also possibly have a trade-off of raising the false matches

"Answer C" and "**Answer** (B)" now extract the letter. Without a colon,
the letter must be on the same line, uppercase, and stand alone or label
an option, so prose such as "answer a) first" or "answer A good question"
does not match. This matters because the ANSWER pattern outranks
\boxed{}, so an early false match would win over the final answer.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@gregorybchris

Copy link
Copy Markdown
Collaborator Author

@mgmorgan23 I took your advice on the colon change. I'll going to leave the other two out of scope for this PR, but I'm not opposed to returning to this and doing more testing to make sure the changes don't unexpectedly regress something else.

@gregorybchris
gregorybchris enabled auto-merge (squash) October 2, 2026 20:49
@mgmorgan23

Copy link
Copy Markdown
Contributor

That makes sense to me!

@gregorybchris
gregorybchris merged commit 730f206 into main Oct 2, 2026
8 checks passed
@gregorybchris
gregorybchris deleted the chrisg/fix-mcq-letter-extraction branch October 2, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants