Show your work: make the AI cite its sources

If you have an AI write docs about your code, make it show its work: a file and line number for every claim. When I did that to a set of architecture docs, it found about 130 claims that were wrong.

How I got here

When I started a new job, I had Claude map out a large codebase I'd never seen: Mermaid diagrams (a way to write flowcharts and sequence diagrams as text), a table of contents, the works. It was a great way to learn the system.

Then GitHub's Copilot reviewed the pull request and found 19 factual errors. Every one was real. Classes with the same name in two places, mixed up. A service whose name sounded bigger than what it actually did. Dead code described as if it ran.

The docs read fine. That's the problem. A plausible wrong sentence costs as much to check as it took to write, and nobody checks.

The ask

Later I had Claude write another set of docs, about how the different parts of the system talk to each other. Before I trusted them, I asked for this:

For each claim we've made in the architecture documents, add code references with line numbers and file names, whatever led you to the diagram you made, so I can cross check it. A bulleted list or table underneath each might be better.

Claude spun up one agent per document, twelve in parallel. Each one added a Sources table under each diagram. Every row has:

  • the claim
  • the file and line numbers
  • the class or method name, so you can still find it after the line numbers move
  • a status: Verified, Inferred, Unverified, or Corrected

The status is the important part. "Inferred" rows say what reasoning step got there. "Unverified" rows say what the agent searched for and didn't find. Nothing gets to hide as a confident sentence.

What it found

About 1,500 claims across 12 docs. About 130 were wrong, and 29 diagrams changed. A few were big: things the docs said one service created that it actually just looked up, a fallback path that never runs on one device, a deploy that the docs said was automatic and is really started by hand.

It also turned up something in the code itself: a return in a loop where continue looked right, so one bad record could stop a whole sync. That's a possible real bug, found by a docs task.

Claude spot-checked four of the corrections against the code by hand, and all four held up.

Two things worth doing

Put the sources at the bottom. A table under every diagram makes the doc hard to read. We moved all of them to a Sources section at the end of each file, with a link from each section down to its table and back. The evidence is one click away and the doc reads cleanly.

Drop "Corrected" before you merge. A row that says "this used to say X" is great for the reviewer right now. After the merge, it's history in a reference doc, and the next reader doesn't care what it used to say. Flip those to Verified. (I wrote more about that habit in Writing to the prompter.)

Why it works

A claim with a file and line number takes seconds to check. It's a lot harder to make something up when you have to say where you found it.

Bonus: one diagram label got cut off by the preview and just said "the best ho". It was supposed to say "the best host." No source table for that one, I'm afraid.

Drafted with an assistant, edited by @wintaru

0 comments