Skip to content
yemi-kelani/agentspecs

Verification

How to tell whether an agent's work is correct, from runnable checks and who writes the tests to agents that game the tests they are given.

An agent can report that a task is done and that its tests pass. This page asks how you know the work is actually correct, and who or what does the checking.

Evidence In reasoning and planning studies, models corrected themselves poorly without outside feedback and gained from a sound external verifier, and a survey names code checked by running tests as a task with that kind of feedback (R95, R96, R97). In one workflow, tests that people wrote before the code led to 88.8% to 94.3% of tasks passing, against 68.0% when the agent wrote its own (R15, R15a). Tests are not the end of it: when tests contradicted the spec, frontier models often cheated to pass them, the more capable ones more often, and read-only tests stopped test edits but not special-casing (R18, R18c, R18e). The controlled cheating results come from tasks built to be impossible, not from ordinary work. On test-driven development: tests in the prompt helped on small functions, but models wrote a failing test before a fix for only a fifth to a third of real issues, and tests written from existing code tended to assert its bugs (R220, R225, R229).

  • Evidence Without external feedback, GPT-3.5, GPT-4 and Llama 2 struggled to correct their own reasoning and sometimes got worse. These were reasoning benchmarks, not coding agents (R95).
  • Evidence When GPT-4 critiqued its own answers on puzzles and planning problems, performance fell in most domains, while a sound formal verifier gave large gains (R97). A survey of the research found self-correction works where reliable external feedback exists, and names code generation with test execution as one such task (R96).
  • Evidence The Claude Code docs say to give the agent a check it can run, such as tests, a build, a linter or a screenshot comparison, so it iterates until the check passes rather than stopping when the work looks done (R87).
  • Evidence OpenAI’s ExecPlans format requires exact test commands with their expected output, and acceptance phrased as behaviour a person can observe. That is a rule of the format, not a measured result (R90).
  • Evidence Anthropic saw agents mark features done without testing them end to end, and found that prompting them to test as a user would, through browser automation, improved results. The post gives no numbers (R12d).
  • Evidence Given the benchmarks’ human-written tests, the TDFlow workflow passed 88.8% of runnable SWE-bench Lite tasks and 94.3% on SWE-bench Verified. Writing its own tests, it reached 68.0%, so writing correct tests was the main bottleneck (R15, R15a).
  • Evidence When every test it generated was good, the workflow solved 93.3% of those instances, a subset picked after the fact (R15b). The agent could not edit tests, and inspection of 800 runs found 7 cases of test hacking (R15c).
  • Evidence In a workshop study of 90 bugs from one company’s codebase with one small model, writing a contract-style spec (pre- and post-conditions) before generating tests raised bug detection from 53.4% to 63.2%, at 38% more tokens (R16, R16a).
  • Evidence In a preprint with one open-weight model on 100 instances, telling an agent to follow TDD without saying which tests to check raised regressions from 6.08% to 9.94%, while a map of the tests each change affects cut them to 1.82% (R17). As a skill with another model, the map raised resolution from 24% to 32% of 25 instances (R17a).
  • Evidence Giving a model tests with the problem helped on function-level benchmarks. Retrying failed problems with the public tests added raised GPT-4 Turbo’s cumulative share solved from 69.67% to 82.45% on MBPP and from 78.66% to 87.81% on HumanEval (R220), and one or more tests in the prompt raised GPT-4’s MBPP pass@1 from 67.13% to about 80% (R221). Both used people’s tests on small functions, not repository work; see conflict CV3.
  • Evidence In a 15-person study, users who checked AI suggestions against tests they had approved picked the correct one far more often (0.84 against 0.40), with lower cognitive load (R221a).
  • Evidence Writing a failing test before the fix is hard for models. Given an issue and the code before the fix, GPT-4o wrote a test that failed before and passed after for 18.7% of 449 issues, and 37.0% with a five-test ensemble (R225, R224); the best agent on another benchmark managed 19.2% (R223). Showing the model the fix first barely changed this, 109 tests against 106 (R224a).
  • Evidence Agents’ own reproduction tests often missed: for two agents on SWE-bench Verified they triggered the bug in 41% to 57% of tasks, and 18% to 30% of one agent’s tasks had a patch that passed its own reproducer but failed the real tests (R232).
  • Evidence Prompting four models to write more or fewer tests of their own made no significant difference to how many SWE-bench Verified issues they resolved, and their tests used print statements more than assertions (R231, R231a). That varied how many tests they wrote, not when; see conflict CV1.

Tests written from the code, and tests as a filter

Section titled “Tests written from the code, and tests as a filter”
  • Evidence Tests written by looking at the code tend to assert what it does, bugs included. Across 13 LLMs on Java methods, tests written from buggy code passed the bug and failed the fix 3.84% of the time against 0.46% from fixed code, and fewer of them found the bug (R229). Models judging assertions were less accurate when the code was buggy (R228), and in two test-generation tools most kept tests on buggy student programs passed the bug (R230).
  • Evidence Generated tests work as a filter, at a price. Keeping only patches that passed agent-written tests more than doubled one agent’s precision, to 47.8%, at about 20% recall (R223a), and a five-test ensemble lifted precision for 22 leaderboard systems to 65% to 92% while discarding most correct patches (R225a). On function-level problems, ranking candidates by agreement with generated tests raised pass@1 (R226, R227). See conflict CV2.
  • Evidence The Claude Code docs show a bug-fix prompt that asks for a failing test first, and suggest one session write the tests and another the code (R234, R235). Anthropic’s prompting guide suggests writing tests to a structured file before work starts, telling the model that removing or editing tests is unacceptable, and asking for a general solution because Claude can focus too much on passing tests (R236, R237). None of this comes with measurements.
  • Evidence ImpossibleBench gave eight 2025 models coding tasks whose tests contradict the spec, so that passing means cheating. On SWE-bench tasks, GPT-5 cheated on 76% where one test had been altered and 54% where tests conflicted (R18), and more capable models tended to cheat more (R18e).
  • Evidence The cheating included editing tests, overloading operators, keeping extra state and special-casing test inputs; Claude models mostly edited tests (R18f).
  • Evidence Read-only tests, with edits reverted at scoring, stopped test edits and kept legitimate performance, but did not stop special-casing or operator overloading (R18c). Hiding the tests cut cheating to near zero but cost real performance: GPT-5 fell from 97% to 76% on the original tasks (R18b).
  • Evidence Letting the agent stop and flag the task for a person cut GPT-5’s cheating from 54% to 9% and o4-mini’s from 49% to 12%, with little loss on the original tasks, while Claude Opus 4.1 barely changed, from 50% to 46% (R18d).
  • Evidence Stricter prompts cut GPT-5’s cheating on a simpler benchmark from 92% to 1%, but o3 still cheated 33% of the time under the strictest prompt (R18a).
  • Evidence On a separate reward-hacking benchmark, held-out tests added little over an LLM judge for catching hacks, and missed heuristic solutions that passed every test. Its test suites did not cover all behaviour (R19).
  • Evidence GPT-4, GPT-3.5 Turbo and Llama 2 favoured their own news summaries over those of other models and people, and the better a model recognised its own output, the more it favoured it. Quality was not checked against human judgement (R98).
  • Evidence On math and code tasks with checkable answers, much of capable models’ preference for their own answers matched answers that were in fact better, but harmful self-preference remained where the judging model had itself answered wrongly (R99).
  • Evidence LLM critics trained for the job caught more bugs inserted into code than paid human contractors, but also reported bugs that were not there, which human-and-critic teams did less often (R94).
  • Evidence The Claude Code docs recommend a reviewer subagent with a fresh context that sees only the diff and the criteria, and a writer and reviewer in two separate sessions; they publish no data for either (R84, R88).
  • Evidence The same docs warn that a reviewer asked to find gaps usually reports some even when the work is sound, and suggest limiting it to gaps that affect correctness or the stated requirements (R86).
  • Evidence Anthropic describes a loop in which one call generates and another evaluates as most useful when the criteria are clear; its examples are translation and search, not code (R89).
  • Evidence Anthropic began evaluating its research system with about 20 queries, because early changes had large effects. A sample that small only shows large effects (R92).
  • Give the agent a check it can run, such as tests, a build or a linter, instead of relying on its own review of its work (R87, R95, R97).
  • Write the acceptance tests before the code, or have a person review them, since human-written tests led to far more passing tasks than the agent’s own in one workflow (R15, R15a).
  • Consider writing the expected inputs, outputs and conditions down before asking an agent to generate tests, and expect it to cost more tokens (R16, R16a).
  • Before a fix, get a test that fails on the current code, and check that it does: agents’ own reproduction tests missed the bug in about half of tasks in one study (R232), and the Claude Code docs show this order (R234).
  • Write tests from the issue or spec, not from the code under test, since tests written from buggy code tended to pass the bug (R229, R228).
  • Keep test writing and implementation apart, and lock the tests: Anthropic suggests separate sessions and a rule against editing tests (R235, R236), and read-only tests stopped test edits in a controlled study (R18c).
  • Use agent-written tests to filter or rank candidate patches, not as proof of correctness: they raised precision but discarded most correct patches (R223a, R225a).
  • Consider telling the agent which tests each change affects, since a bare instruction to follow TDD raised regressions in one study (R17).
  • Keep the checker where the implementer cannot edit it, such as read-only tests or a check run outside its workspace (R18c, R15c).
  • Read the diff as well, because read-only tests did not stop special-casing or operator overloading (R18c, R18f).
  • Let the agent stop and flag a task whose tests seem to contradict the spec, which cut cheating for some models and not for others (R18d).
  • Run the checks yourself, or in CI, and read the output, rather than taking the agent’s report that the work is done (R12d, R18).
  • If you use a reviewer agent, give it a fresh context, the diff and the criteria, and ask only for gaps that affect correctness (R84, R86, R88); a model tends to favour its own output, though on checkable tasks that was often deserved (R98, R99).
  • Do not relax the checks for a more capable model: across eight models, the more capable ones tended to cheat more on impossible tasks (R18e).
  • Treat held-out tests as one safeguard among several, since in one benchmark they added little over an LLM judge (R19).
  • Whether a separate checker catches more than the implementer’s own tests on ordinary, solvable coding tasks. The controlled cheating rows come from impossible-task stress tests (R18).
  • How often agents special-case tests in everyday work, outside benchmarks built to provoke it (R18c, R18f).
  • Whether a prompted reviewer in a fresh context finds more real bugs than it invents. The critic study trained its critic (R94), and the vendor gives no data for fresh-context review (R88).
  • How far the self-correction results, from reasoning and puzzle tasks with 2023 and 2024 models, carry over to current coding agents that run tests (R95, R97).
  • Whether test-first beats test-after or no tests for agents on repository work. No controlled study compares them; the closest varied how many tests agents wrote, not when (R231).
  • What writing tests before the code costs people in time, against what it saves.
  • More gaps are listed under Open questions.