Search and code (default)
All steps
A date is wrong, then fixed
Verified first time
Parts of this pattern
- Question Input / output
- 'When did the Golden Gate Bridge open, and how long was it the world's longest suspension span?'
- Model LLM call
- Answers the question, then rewrites the answer whenever its own verification finds a claim the evidence contradicts.
- Verifier LLM call
- The same model under a verification prompt: it picks the checkable claims, calls tools on them and returns OK or the wrong claims.
- Web search Tool
- Looks up facts such as dates and names, and returns snippets the verifier can quote as evidence.
- Python Tool
- Runs short calculations, such as the number of years between two dates, so arithmetic is computed, not recalled.
- Answer Input / output
- The answer once a verification round finds every checked claim agrees with the evidence.
- Question → Model
- The question goes to the model, which answers from what it knows.
When did the Golden Gate Bridge open, and how long was it the world's longest suspension span?
- Model → Verifier
- The answer goes to the verification prompt, unchanged.
It opened in 1936 and held the record for 27 years, until the Verrazzano-Narrows Bridge opened in 1964.
- Verifier → Web searchcheck
- The verifier turns each factual claim into a search.
Golden Gate Bridge opening date
- Web search → Verifierevidence
- Search results come back as evidence to quote.
The Golden Gate Bridge opened to the public on May 27, 1937. (Wikipedia)
- Verifier → Python
- For arithmetic claims, the verifier runs code instead of trusting the number in the answer.
print(1964 - 1937)
- Python → Verifier
- The computed value comes back to the verifier.
27 (printed by the code)
- Verifier → Modelrevise
- A critique quoting the evidence goes back, and the model rewrites only the wrong claims.
WRONG: 'opened in 1936'. Search: opened to the public May 27, 1937. The span held the record from 1937 to 1964.
- Verifier → AnswerOK
- When every checked claim agrees with the evidence, the answer is returned.
It opened on May 27, 1937 and was the world's longest suspension span for 27 years, until 1964.
Code and tests (Self-Debug)
For code: the model runs its program against tests, explains the code line by line next to the failures, and fixes it from that explanation.
All steps
Parts of this pattern
- Task Input / output
- A coding task with visible tests: 'Write median(xs) for a list of numbers.'
- Model LLM call
- Writes the first version of the code, then writes each fixed version from the explanation of what went wrong.
- Test runner Tool
- Runs the code against the visible tests and returns, for each failure, the input, the expected and the actual output.
- Explain LLM call
- The same model under an explanation prompt: walks through its code line by line and pins down where it diverges from the failing test.
- Code Input / output
- The version of the code that passes every visible test.
- Task → Model
- The task and its visible tests go to the model.
Write median(xs). Tests: median([3, 1, 2]) == 2; median([4, 1, 3, 2]) == 2.5
- Model → Test runnerrun
- Each version of the code is run against the tests.
def median(xs): s = sorted(xs); return s[len(s) // 2]
- Test runner → Explainfailures
- Failing tests go to the explanation step with their expected and actual output. The runner only reports; it does not explain.
median([4, 1, 3, 2]): expected 2.5, got 3
- Explain → Modelexplanation
- The line-by-line explanation goes back to the model, which writes a fix aimed at exactly the line it names.
sorted(xs) gives [1, 2, 3, 4]; s[len(s) // 2] returns s[2] = 3, the upper middle. For an even length the median is the mean of s[1] and s[2], 2.5, so the return is wrong when len(s) is even.
- Test runner → Codeall pass
- When every test passes, that version is returned.
def median(xs): s = sorted(xs); n = len(s); return s[n // 2] if n % 2 else (s[n // 2 - 1] + s[n // 2]) / 2
← → neighboursesc atlas
CRITIC
Also known as Tool-interactive critiquing · Verify-then-revise · Tool-verified self-correction
The model drafts an answer, checks its own claims with tools such as search or code, and revises from the evidence they return.
Search and code: Introduced by Gou et al. (2023) · Tsinghua University, Microsoft Research Asia and others
Published at ICLR 2024. The paper's point is that models correct themselves poorly from introspection alone, and reliably once a tool supplies evidence.
Code and tests (Self-Debug): Introduced by Chen et al. (2023) · Google DeepMind & UC Berkeley
Self-Debugging: the model explains its own code, rubber-duck style, alongside unit test results and execution traces, then fixes it, with no human feedback.
Measured over one run
Search and code
- Nodes
- 6. Boxes in the diagram: models, tools, stores, people and plain code.
- LLM calls
- 4. Model invocations in the first scenario: each time a model or agent node starts thinking, plus each branch it decides.
- Tool calls
- 3. Messages sent to a tool node in the first scenario.
- Steps
- 6. Steps in the first scenario, with repeated steps counted every time they run.
- Scenarios
- 2. Distinct example runs you can switch between on the diagram.
- Loop
- yes. Whether the flow cycles back on itself until a condition is met.
- Parallel
- no. Whether two or more messages are in flight at the same time.
- Branch
- yes. Whether the flow takes one path out of several, chosen at run time.
- Human in the loop
- no. Whether a person appears as a node, to approve, correct or answer.
- Autonomy
- medium. How much the model decides the control flow itself, from fixed code paths (low) to open-ended (high).
- Cost
- medium. Relative token spend per request.
- Latency
- high. Relative wall-clock time per request.
Code and tests (Self-Debug)
- Nodes
- 5. Boxes in the diagram: models, tools, stores, people and plain code.
- LLM calls
- 3. Model invocations in the first scenario: each time a model or agent node starts thinking, plus each branch it decides.
- Tool calls
- 2. Messages sent to a tool node in the first scenario.
- Steps
- 4. Steps in the first scenario, with repeated steps counted every time they run.
- Scenarios
- 1. Distinct example runs you can switch between on the diagram.
- Loop
- yes. Whether the flow cycles back on itself until a condition is met.
- Parallel
- no. Whether two or more messages are in flight at the same time.
- Branch
- yes. Whether the flow takes one path out of several, chosen at run time.
- Human in the loop
- no. Whether a person appears as a node, to approve, correct or answer.
- Autonomy
- medium. How much the model decides the control flow itself, from fixed code paths (low) to open-ended (high).
- Cost
- medium. Relative token spend per request.
- Latency
- high. Relative wall-clock time per request.
Counted from the first scenario's timeline when the site is built.
Problem
Ask a model “When did the Golden Gate Bridge open, and how long was it the world’s longest suspension span?” and it may answer “1936” with full confidence. Ask it to review its own answer and it will often confirm the mistake, because the review draws on the same memory that produced it. Gou et al. found that a model’s self-critique on its own is unreliable and can even make answers worse. What is missing is something outside the model to check against.
How it works
CRITIC, from Gou et al., adds that outside check. The model first answers the question as usual. The answer then goes to the verifier, the same model under a verification prompt. Its job is to list the claims that a tool could check, the dates, numbers and names, and to check each one.
Here the verifier asks web search for the opening date and gets back “opened to the public May 27, 1937”. It also uses Python for the arithmetic, 1964 minus 1937, rather than trusting the 27 years in the answer. The date contradicts the evidence, so the verifier sends a critique back that names the wrong claim and quotes the search result.
The model revises only that claim. The new answer goes through verification again from the start; this time the search agrees, the verdict is OK, and the answer goes to the output.
The critique loop passes through a tool. That is the whole difference from plain self-critique: every correction rests on evidence the model did not produce.
Not the same as Evaluator-Optimizer. Evaluator-Optimizer’s Tool-checked variant, which also cites the CRITIC paper, is the workflow form of this idea. A separate evaluator, with criteria you wrote, judges a generator’s draft and uses tools to do it. CRITIC as an agent loop is narrower and more autonomous. One model checks its own answer, decides for itself which claims need checking and which tool to use, and its only standard is whether the evidence agrees. Choose Evaluator-Optimizer when you have explicit acceptance criteria. Choose CRITIC when the question is simply “is what I said true?”.
The Code and tests (Self-Debug) variant. For code, the tool is a test runner. In Chen et al.’s Self-Debugging, the model runs its program against the visible tests, explains its own code line by line next to the failures, and fixes it. Explaining the code, like rubber duck debugging, is what helps it find the bug when the tests only say “expected 2.5, got 3”. The build makes the explanation and the fix two calls to the same model, so the explanation shows up in the logs.
When to use
- Answers contain checkable facts, numbers or code, and being wrong is costly.
- You have tools that can check them: search, a database, a calculator, an interpreter, tests.
- The model’s introspection has proved unreliable for your task, so plain self-review keeps missing errors.
When to avoid
- No tool can check the output, as with tone, style or opinion. Without evidence, this collapses into self-critique. Use Evaluator-Optimizer with a clear rubric instead.
- Latency matters. Every answer costs at least one more model call plus tool calls, and every revision adds another round.
- The tools are less reliable than the model, for example a search over poor sources. Then the evidence can talk the model out of a correct answer.
Trade-offs
CRITIC spends extra calls to replace confidence with evidence. When an answer is right first time, verification still costs a model call and a few tool calls. When it is wrong, you get a correction tied to a source you can show to a user. The quality ceiling is set by the tools: a verifier is only as good as what it can look up or compute. It also corrects within one attempt only. Nothing is learned for the next question, which is what Reflexion’s memory adds.
Failure modes
- Checking the easy claims: the verifier checks a trivial detail and skips the claim that matters. Ask it to list every checkable claim before it calls any tool.
- Evidence-free critique: the verifier objects from memory, without quoting a tool result. Reject critiques that quote no evidence.
- Bad evidence wins: a weak search result overrides a correct answer. Prefer authoritative sources, and log the evidence behind every change.
- Revision drift: fixing one claim rewrites others. Tell the model to keep everything that was not criticised, and verify the whole answer again.
Build it with your AI
Search and code
Paste this into Claude Code, Cursor, ChatGPT or any AI coding assistant.
Implement the CRITIC pattern in this codebase, using the LLM client and language we already use.
## Goal
Answer a question, then have the same model verify the answer's claims with tools and revise it from the evidence, until a verification round finds nothing wrong.
## How it works
1. Call the model with the question to get a first answer.
2. Call the same model with the Verification prompt, the question, the answer and the tool definitions. It lists the claims a tool can check and requests the tool calls.
3. Run each requested call (a search, a code execution, a calculation) and return the results, or their errors, to the model.
4. Parse the model's verdict: either OK, or a critique that names each wrong claim and quotes the evidence.
5. If the verdict is OK, return the answer. Otherwise call the model with the Revision prompt, passing the question, the answer and the critique, and verify the revised answer from the start.
## Prompts
### Verification prompt
```markdown
Check the answer below before it is shown to anyone. You have tools.
<question>{{question}}</question>
<answer>{{answer}}</answer>
1. List every claim in the answer that a tool could check: dates, numbers,
names, quotations, calculations.
2. Use the tools to check each one. Do not rely on memory.
3. Then reply with exactly one of:
OK
or
WRONG: one line per wrong claim, with the tool evidence that contradicts it.
```
### Revision prompt
```markdown
Your answer contained claims that the evidence contradicts.
<question>{{question}}</question>
<answer>{{answer}}</answer>
<critique>{{critique}}</critique>
Rewrite the answer so that every claim agrees with the evidence.
Keep everything that was not criticised. Return only the revised answer.
```
## Stop rule
Stop when a verification round finds no wrong claim, or after 3 revisions. On the cap, return the last answer with its unresolved critique and a status saying it was not verified.
## Requirements
- Use one model for answering, verifying and revising; only the prompt changes.
- Give the verifier read-only tools with timeouts, and cap tool calls per round (default 5) as well as revisions (default 3).
- Accept a critique only if it quotes a tool result; a critique without evidence counts as OK, so the model cannot argue itself out of a correct answer.
- Log every claim checked, the tool call that checked it, the result and the verdict.
- Add a test with a stub LLM that first answers 1936 and a fake search that returns 1937; assert the critique quotes 1937, one revision happens, and the returned answer says 1937.
Code and tests (Self-Debug)
Paste this into Claude Code, Cursor, ChatGPT or any AI coding assistant.
Implement the CRITIC pattern (Code and tests (Self-Debug) variant) in this codebase, using the LLM client and language we already use.
## Goal
Generate code for a task, run it against the available tests, and have the same model explain its code against the failures and then fix it, until the tests pass.
## How it works
1. Call the model with the task and the visible tests to write the first version of the code.
2. Run the code against the tests in a sandbox and capture, for each failing test, the input, the expected output, the actual output or the error.
3. If every test passes, return the code.
4. Otherwise call the same model with the Explanation prompt, passing the code and the failing test results. It explains the code line by line and says where its behaviour differs from what the tests expect, without writing code.
5. Call the model with the Fix prompt, passing the code, the failures and that explanation, to write a complete fixed version.
6. Run the fixed version against the tests and repeat.
## Prompts
### Explanation prompt
```markdown
Your code fails some tests.
<task>{{task}}</task>
<code>{{code}}</code>
<failures>{{failing_tests_with_expected_and_actual}}</failures>
Explain what the code does, line by line, as if to a colleague.
Then trace one failing test through it and say exactly where its
behaviour differs from what the test expects. Do not write code.
```
### Fix prompt
```markdown
<task>{{task}}</task>
<code>{{code}}</code>
<failures>{{failing_tests_with_expected_and_actual}}</failures>
<explanation>{{explanation}}</explanation>
Using the explanation, fix the code so every failing test passes
without breaking the ones that pass. Return the complete fixed code
in one code block, with no commentary.
```
## Stop rule
Stop when every visible test passes, or after 3 debugging rounds. On the cap, return the version that passed the most tests, with the failures that remain.
## Requirements
- Run code in a sandbox with time and memory limits; treat a timeout as a failing test with the message 'timed out'.
- Pass the actual output and the expected output for every failing test, not only a pass/fail count.
- Keep every version, its test results and its explanation, and return the best version if the cap is hit.
- Do not show the model hidden tests; check the final code against them separately, if you have them.
- Add a test with a stub LLM whose first program fails one test and whose second passes all; assert one explain call, one fix call, two test runs, and that the second program is returned.
Prompt templates
Search and code
Check the answer below before it is shown to anyone. You have tools.
<question>{{question}}</question><answer>{{answer}}</answer>
1. List every claim in the answer that a tool could check: dates, numbers, names, quotations, calculations.2. Use the tools to check each one. Do not rely on memory.3. Then reply with exactly one of: OK or WRONG: one line per wrong claim, with the tool evidence that contradicts it.Your answer contained claims that the evidence contradicts.
<question>{{question}}</question><answer>{{answer}}</answer><critique>{{critique}}</critique>
Rewrite the answer so that every claim agrees with the evidence.Keep everything that was not criticised. Return only the revised answer.Code and tests (Self-Debug)
Your code fails some tests.
<task>{{task}}</task><code>{{code}}</code><failures>{{failing_tests_with_expected_and_actual}}</failures>
Explain what the code does, line by line, as if to a colleague.Then trace one failing test through it and say exactly where itsbehaviour differs from what the test expects. Do not write code.<task>{{task}}</task><code>{{code}}</code><failures>{{failing_tests_with_expected_and_actual}}</failures><explanation>{{explanation}}</explanation>
Using the explanation, fix the code so every failing test passeswithout breaking the ones that pass. Return the complete fixed codein one code block, with no commentary.Related patterns
Composes well with:
Sources
From the Agentic Atlas by Joran Kikke · Edit on GitHub · Suggest a correction