Repository navigation
Conversation
When models like Sonnet 4.6 generate code blocks and FINAL() in the same response, the FINAL() is based on hallucinated execution output rather than actual results. Skip text-based FINAL() detection when code blocks are present, forcing real execution results to be fed back so the model can answer correctly in the next turn. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Can't you just use a stop token at the end of the |
|
This is a weird problem that's quite model dependent, let me think on it more. Ideally we'd like to have less hacky solutions to this... |
|
Adding a concrete repro for #127 in case it helps with prioritization. Repro (
Context: this lives in a downstream production code-review pipeline doing
The full-mode path is globally disabled in our config until #127 merges. |
|
Follow-up to my earlier comment — I dug deeper and want to correct the framing. PR #127 appears to be superseded by main. Commit I verified against All three pass on Two notes that might be useful:
Happy to open a PR with the regression tests against |
|
Thank you for digging in to this - The problem has been resolved by the dict-based fix. I'll close this PR. |
Problem
Claude 4.6 models (Sonnet and Opus) behave differently from earlier models when generating RLM responses. Instead of generating a code block and stopping to wait for execution feedback, these models continue generating past the code block — they hallucinate what they think the execution output will be, reason over that hallucinated output, and then commit to a
FINAL()answer, all within a single turn.For example, when asked "Which are the top 10 most spending customers?" with real customer data in
context, Sonnet 4.6 would:print(context)inside a```repl ```block (correct)FINAL(1. Kevin: $5200, 2. Hannah: $4500, ...)— a confidently wrong answer based on hallucinated dataThe code blocks are executed correctly and produce the real results, but because
find_final_answer()finds theFINAL()in the same response, the completion loop exits immediately. The real execution results are never fed back to the model, and the hallucinated answer is returned as-is.This is a fundamental mismatch: the RLM loop assumes models will stop after generating a code block and wait for feedback, but Claude 4.6 models do not — they eagerly generate the full response, including predicted outputs and final answers, in one shot.
Fix
Skip text-based
FINAL()detection when the response contains code blocks. If code blocks are present, the model may have hallucinated the output, so we discard anyFINAL()found in the response text and instead feed back the real execution results viaformat_iteration(). The model then sees the actual data and provides the correct answer in the next turn.This does not affect:
FINAL_VAR()from code execution — still works, since it retrieves real variables from the REPLFINAL()in text-only responses (no code blocks) — still works, since the model is answering based on results it received in prior turnsVerification