Fix hallucinated FINAL() answers with Claude 4.6 models#127
Open
huiwenn wants to merge 1 commit intoalexzhang13:mainfrom
Open
Fix hallucinated FINAL() answers with Claude 4.6 models#127huiwenn wants to merge 1 commit intoalexzhang13:mainfrom
huiwenn wants to merge 1 commit intoalexzhang13:mainfrom
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 |
Owner
|
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... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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