Skip to content

qed_math_env: ignore <score> tags inside <assessment>/<errors> and strip grader tags from submitted proofs - #1698

Open
fayaz316 wants to merge 4 commits into
openenv:mainfrom
fayaz316:fix/qed-math-rubric-score-tags
Open

fayaz316 wants to merge 4 commits into
openenv:mainfrom
fayaz316:fix/qed-math-rubric-score-tags

Conversation

@fayaz316

@fayaz316 fayaz316 commented Nov 22, 2026 •

Copy link
Copy Markdown

Summary

Hi! Thanks for porting and maintaining qed_math_env and its test suite.

While reading MathProofRubric (envs/qed_math_env/server/rubric.py), I noticed a small edge case in how <score>N</score> tags are extracted:

  • MathProofRubric._parse_response uses re.search(r"<score>(\d+)</score>", text), so the first <score>N</score> anywhere in the grader response becomes the grade.
  • _build_prompt embeds the submitted proof verbatim. Under v0.md (where <assessment> precedes <score>) or the fallback prompt, if the grader quotes a <score>7</score> from the proof inside its assessment before emitting its verdict <score>1</score>, re.search picks the quoted 7.
  • Under v1.md (the default) and v2.md, <score> comes first before <assessment>, so switching blindly to last-match would break v1.md/v2.md if the grader quotes a tag inside <assessment>.
grader response shape grader's own tag current parsed score reward
<assessment>...</assessment><score>6</score> (v0 / fallback) 6 6 0.857
<assessment>Proof writes <score>7</score>...</assessment><score>1</score> 1 7 1.0
<score>1</score><assessment>Proof writes <score>7</score>...</assessment> (v1/v2) 1 1 0.143

This PR:

  1. Strips <assessment>...</assessment> and <errors>...</errors> blocks in _parse_response before extracting <score>N</score> (taking the last remaining match for unstructured fallback responses).
  2. Strips <score>, <assessment>, and <errors> tags (case-insensitive) from proof in _build_prompt.

Scope note: this prevents quoted or injected XML tags in the proof from interfering with score extraction across v0.md, v1.md, v2.md, and fallback prompts; general prompt injection (where an LLM grader follows plain-text instructions in the proof to emit a higher score) remains a prompt-level limitation.

Type of Change

  • Bug fix

RFC Status

  • Not required (bug fix, docs, minor refactoring)

Test Plan

Added unit tests in tests/envs/test_qed_math_environment.py:

  • v0 shape: quoted <score>7</score> inside <assessment> before closing <score>1</score> -> 1
  • v1/v2 shape: leading <score>1</score> followed by quoted <score>7</score> inside <assessment> (including truncated <assessment>) -> 1
  • fallback shape: earlier <score>7</score> followed by closing <score>1</score> -> 1
  • existing clamping ([0, MAX_SCORE]) and missing-tag (0) behavior unchanged
  • _build_prompt strips <score>, <assessment>, and <errors> tags (case-insensitive) from proof

Note

Medium Risk
Changes core reward parsing for proof grading; incorrect regex could mis-score submissions, but behavior is covered by new unit tests and existing clamping/missing-tag paths are unchanged.

Overview
Fixes incorrect proof scores when the LLM grader quotes <score> tags from the submission inside <assessment> / <errors> prose, which previously made _parse_response pick the first tag anywhere in the response instead of the verdict.

MathProofRubric now strips closed and unclosed assessment/errors blocks before finding <score>N</score>, uses the last remaining match (with a fallback path), and removes <score>, <assessment>, and <errors> tags from submitted proofs in _build_prompt so injected markup cannot pollute the grader prompt.

Unit tests cover v0/v1 response shapes, truncated assessments, self-closing tags, and prompt sanitization.

Reviewed by Cursor Bugbot for commit b04549e. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit eb92b0c. Configure here.

Comment thread envs/qed_math_env/server/rubric.py Resolved

This branch has not been deployed

No deployments
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.

1 participant