Introduction to Reasoning › Checking and Refining Reasoning

Michael BrenndoerferJune 21, 20252 min read
AI Agent HandbookAll chapters
Part 4 of 15Reasoning - Teaching the Agent to Think
Chapter 9Introduction to Reasoning › Checking and Refining Reasoning
Reading section 7 of 14 · Checking and Refining Reasoning · 2 minSection 7 of 14 · 2 min

Book contents

Section 7 of 14 · 2 min read

Introduction to Reasoning › Checking and Refining ReasoningOne section · Sections in this chapter7 / 14 ↓

One powerful aspect of chain-of-thought prompting is that it makes the agent's thinking visible. This means you can check whether the reasoning makes sense, even if you're not sure about the final answer.

But we can go further. We can actually prompt the agent to check its own work.

Self-Verification

After the agent provides an answer with reasoning, you can ask it to verify:

Question: [Original question]
Answer: [Agent's answer with reasoning]

Now double-check this answer. Is the reasoning sound? Are there any errors?

This prompts the agent to review its work from a critical perspective. Sometimes this catches mistakes that slipped through the first time.

Example (GPT-5)

Here's how you might implement self-verification:

In[2]:
Code
from openai import OpenAI

client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

## First, get the agent's answer with reasoning
initial_response = client.chat.completions.create(
    model="gpt-5",
    messages=[
        {
            "role": "user",
            "content": """A store has a 20% off sale. If a shirt originally costs \$40, and you have a coupon for an additional \$5 off, what's the final price?

Let's calculate this step by step.""",
        }
    ],
)

initial_answer = initial_response.choices[0].message.content
print("Initial answer:", initial_answer)

## Now ask the agent to verify
verification_response = client.chat.completions.create(
    model="gpt-5",
    messages=[
        {
            "role": "user",
            "content": f"""Here's a solution to a problem:

{initial_answer}

Please review this solution carefully. Is the reasoning correct? Are there any errors? If there are mistakes, provide the corrected solution.""",
        }
    ],
)

print("\nVerification:", verification_response.choices[0].message.content)

This two-step process can catch errors. For instance, the agent might initially apply the $5 coupon before the 20% discount, when the correct order might be to apply the percentage discount first. The verification step gives it a chance to reconsider.

For intermediate readers: This self-verification technique works because language models are better at evaluating text than generating it perfectly on the first try. When you ask the model to critique its own reasoning, you're essentially running a second inference pass with a different framing. The model can spot inconsistencies or errors in the reasoning chain that it might have missed when generating the original response. This is similar to how humans often catch their own mistakes when proofreading. However, it's not foolproof. The model might reinforce an error if it's confident in the wrong answer. For critical applications, you'd want human review or multiple independent reasoning paths.