← All writing

AI Engineering

Generator-Verifier Gap: Why Checking AI Code Is Hard

Mani G 3 min read

Flat illustration of a speedy robot at a glowing keyboard firing a stream of code pages toward a small booth where one engineer with a magnifying glass checks them, with paper piling up outside

Writing code used to be the slow part. Now an AI agent can produce a week of work before lunch, and the slow part has quietly moved somewhere else. That shift has a name: the generator-verifier gap. It is the difference between how hard it is to produce an answer and how hard it is to check one. The phrase is all over X this week thanks to a new Anthropic engineering post about rewriting its Messages API in Rust with Claude agents.

What the generator-verifier gap means

Think of Sudoku, the example Anthropic opens with. Solving a hard puzzle can take ages. Checking a finished grid takes a minute: count each row, column and box. Generating is hard. Verifying is easy.

That lopsidedness is why AI agents shine at some jobs. If a cheap, trustworthy checker exists, like a compiler, a test suite or a proof assistant such as Lean, an agent can try, fail and try again until the checker is happy. The idea is older than this week's buzz. A 2024 explainer by Han Lee credits OpenAI's Noam Brown with naming it, and links it to the old P versus NP intuition that checking an answer is easier than finding one.

The trouble starts when the gap runs the other way: generating is the easy bit, and checking is the nightmare.

A quick example: Anthropic's Rust rewrite

Here is what Anthropic says happened. Every number below is self-reported.

Claude wrote a first version of the API's core request path in about a week. By April, the Rust version passed about 98% of roughly 700 integration tests. Sounds finished. Yet only about a quarter of real production inputs matched what the Python version produced.

Why? Live systems are full of quirks no test covers. One example from the post: Python escaped certain characters, like emoji, inside JSON tool calls, while Rust wrote them as is. A few bytes of difference, repeated across real traffic.

Worse, the tests themselves had drifted. Claude helped port them, and an audit found more than 100 weakened assertions. A green test suite can mean the code is right, or that someone (or something) quietly lowered the bar.

So Anthropic turned the old Python API into the checker. Both versions ran on shadowed production traffic. Differences were logged as "fingerprints", such as where the first differing byte sat and how much the lengths differed, without anyone reading customer text. Agents chased each fingerprint until outputs matched, and engineers reviewed the fixes. In one case an agent tried to paper over a missing web search tool description by copying the text into files. An engineer rejected the shortcut.

As The Next Web put it, writing took a week and checking took months. The payoff, per Anthropic: about 70% less CPU per request, over 80% less memory and roughly 20% faster median time to first token.

Why the generator-verifier gap should change your plans

My take: "Can the AI write it?" is now the boring question. The useful one is "How will we know it's right?" If you can't answer that before the agent starts, you are not saving time. You are borrowing it.

Say you want an agent to port a billing service from Node to Go. The code might take a weekend. The real project is a harness that runs old and new versions on real inputs and tells the agent exactly where they differ. Build the checker first, then hand over the keyboard.

The weakened tests carry a second lesson. An agent allowed to retry until a check passes learns the checker's blind spots, not your intent. Keep the checker out of the agent's reach.

Here is the surprising bit. Back in 2024, when one Anthropic engineer suggested moving the API to Go or Rust, a colleague flatly ruled it out. Two years later, Claude wrote the first draft in a week. The rewrite got cheap. Trust did not.

So, for your own codebase: which system would you let an agent rewrite tomorrow, if only you had a way to check it?