Find the First Wrong Step in Math, Hints Only
A prompt that identifies the first incorrect step in a math solution and gives a hint without revealing the final answer or full derivation.
When a student works through a math problem and arrives at the wrong result, asking an AI model to review the work often causes the assistant to output the complete corrected derivation along with the final answer. This removes the opportunity for self-correction. What the learner needs is a targeted indicator pointing out the single line where the calculation first diverged, accompanied by a concise hint on what principle to reconsider.
Constraining AI output to specific fields rather than full rewrites follows the same principle as extracting changes in a table.
[1] A generic query exposes the full solution immediately. Consider a system of linear equations with an algebraic transposition error inserted into Line 4 of a 6-line student solution.
I solved the following system of linear equations, but my answer is wrong. Please let me know where I made a mistake. [Problem]3x + 2y = 16 ...(1)x - y = 2 ...(2) [My Solution][Line 1] From equation (2), express x in terms of y: x = y + 2[Line 2] Substitute x into equation (1): 3(y + 2) + 2y = 16[Line 3] Expand the parenthesis: 3y + 6 + 2y = 16[Line 4] Combine like terms and transpose 6: 5y = 16 + 6[Line 5] Simplify the right side: 5y = 22[Line 6] Divide both sides by 5: y = 22/5Running this with Claude 5.5 Sonnet demonstrates the problem.
$ claude -p --model claude-sonnet-5-5 --max-turns 1 --tools "" --setting-sources "" --strict-mcp-config < run/bad.en.prompt.txt > run/bad.en.out.txt$ cat run/bad.en.out.txtThe mistake is in **Line 4**. When you move 6 to the right side, its sign must change. Moving +6 across the equals sign gives −6, not +6: 3y + 6 + 2y = 16 → 5y = 16 **−** 6 → 5y = 10 Lines 5 and 6 then become: - Line 5: 5y = 10- Line 6: y = 2 Substituting back: x = y + 2 = 4. Check: 3(4) + 2(2) = 16 ✓ and 4 − 2 = 2 ✓ **Answer: x = 4, y = 2**The model correctly flags Line 4, but immediately calculates 5y = 10, y = 2, x = 4, and supplies verification. The learner has no room left to rework the equation independently.
[2] Redesign the prompt. Anthropic's prompt engineering guidelines advise stating the specific actions the model should take instead of only listing what it must not do.
Direct the model to verify each step sequentially from Line 1, isolate only the single line where an error first appears, and format the output strictly as the line number and a 1-2 sentence hint.
Review the student's math solution, identify the first line where a calculation or logical error occurs, and provide only a hint for self-correction. [Rules]1. Check each line sequentially starting from Line 1 to verify logical equivalence with the previous step.2. Even if multiple subsequent lines contain errors, identify only the single line where the error first occurred. Do not mention subsequent lines.3. Do not reveal the final answers (the correct values of x or y) or the fully corrected equations.4. Give only a 1-2 sentence hint prompting the student to think about signs, transposition, or arithmetic rules.5. Output only in the exact format below without any additional commentary or greeting. [Output Format]Incorrect Line: [Line number]Hint: [1-2 sentence hint] [Problem]{problem} [Student Solution]{student_solution}[3] Run the prompt with the system of equations and the 6-line student solution.
$ claude -p --model claude-sonnet-5-5 --max-turns 1 --tools "" --setting-sources "" --strict-mcp-config < run/good.en.prompt.txt > run/good.en.1.out.txt$ cat run/good.en.1.out.txtIncorrect Line: 4Hint: When you move a term to the other side of the equation, think about what happens to its sign. Check whether adding 6 to the right side is really the same as moving it across the equals sign.The model isolates Line 4 without leaking y = 2, x = 4, or 5y = 10. It directs attention specifically to the transposition operation in Line 4.
A second execution under the same parameters (good.en.2.out.txt) confirms consistency:
Incorrect Line: 4Hint: When you move a term to the other side of the equation, think about what happens to its sign. Check whether adding 6 to the right side is the correct operation.Both runs named Line 4. The hints differ: run 1 asks about the sign change when a term moves across the equals sign, run 2 asks whether adding 6 to the right side is the correct operation.
[4] Validate the output using an automated verification script. The script checks that the line number matches the planted error, that the format matches the specification, and that the output contains none of a fixed list of answer fragments for this one problem (x = 4, y = 2, (4, 2), 5y = 10, 16 - 6, Answer:). It searches only that list.
#!/usr/bin/env python3"""Math hint checker: verify the output names the right line and matches a fixed list of leak patterns."""import sys, re def check(output_path, expected_line): with open(output_path, "r", encoding="utf-8") as f: text = f.read().strip() expected_line = int(expected_line) errors = [] m_line = re.search(r"Incorrect\s*Line\s*:\s*(\d+)", text, re.I) m_hint = re.search(r"Hint\s*:\s*(.+)", text, re.I) if not m_line: errors.append("format error: no 'Incorrect Line: N' found") line_num = None else: line_num = int(m_line.group(1)) if line_num != expected_line: errors.append(f"wrong line: expected {expected_line}, model said {line_num}") if not m_hint or not m_hint.group(1).strip(): errors.append("missing hint: the Hint line is absent or empty") # Only these fixed patterns for this one problem are searched (x=4, y=2, 5y=10, 16-6). leak_patterns = [ r"(?<![0-9a-zA-Z])x\s*=\s*4(?![0-9])", r"(?<![0-9a-zA-Z])y\s*=\s*2(?![0-9])", r"\(\s*4\s*,\s*2\s*\)", r"(?<![0-9a-zA-Z])5y\s*=\s*10(?![0-9])", r"16\s*[-\u2212]\s*6", r"Answer\s*:\s*", ] for pat in leak_patterns: m_leak = re.search(pat, text, re.I) if m_leak: errors.append(f"leak pattern found: '{m_leak.group(0)}'") if errors: print("FAIL:") for err in errors: print(f" - {err}") return False print(f"PASS: line {line_num} named, no listed leak pattern found, hint line present") return True if __name__ == "__main__": if len(sys.argv) < 3: print("Usage: python check_en.py <output_file> <expected_line>") sys.exit(2) sys.exit(0 if check(sys.argv[1], sys.argv[2]) else 1)Run the checker against the English output:
$ python run/check_en.py run/good.en.1.out.txt 4PASS: line 4 named, no listed leak pattern found, hint line presentTwo hand-made bad outputs test the script, one naming Line 3 and one with the answer written into the hint (fake_wrong_line_en.txt, fake_leak_en.txt). Both exit with code 1. The leaked-equation case looks like this (not a model output):
$ python run/check_en.py run/fake_leak_en.txt 4FAIL: - leak pattern found: 'x = 4' - leak pattern found: 'y = 2' - leak pattern found: '5y = 10' - leak pattern found: '16 - 6'[5] Limitations and operational details.
- The checker only matches fixed strings. A hand-made output that spells the answer out in words (
fake_spelled_en.txt: "The solution is x equals four and y equals two.") still printsPASS; see the test output below the list (not a model output). Read the hint yourself to judge whether it gives the answer away. - The run 2 hint asks whether adding 6 to the right side is the correct operation, which points close to the correct step
5y = 16 - 6. The checker passed it. A hint can contain no answer fragment and still be very specific, so judge that by reading. - Only inputs with
[Line 1],[Line 2]labels were tested. Solutions without labels, whether the model names Line 5 or 6 when the error carries forward from Line 4, and geometry or proof problems were not tested in this run.
$ python run/check_en.py run/fake_spelled_en.txt 4PASS: line 4 named, no listed leak pattern found, hint line present