Back to the blog
Engineering

Give Your Coding AI a Way to Know It Got It Right

We asked Claude Code to build a RAG over a Central Bank of Brazil report, with and without an eval. With it, the system got more right, especially on charts. Without it, the AI made up an easy test and gave itself full marks.

12 min read

Claude CodeEvalsRAGPython
In this article9 sections
  1. 01The experiment
  2. 02Results
  3. 03Without an eval, the AI made up its own test
  4. 04With an eval, the AI went after the charts
  5. 05But the eval also misled
  6. 06What none of the four did
  7. 07Recipe: how to give your coding AI an eval
  8. 08Limitations
  9. 09The code

Getting an AI to write code is easy now. The hard part is knowing whether the code is right.

With a 50-line script, you read it and check. With a RAG system, with PDF extraction, search and a prompt, reading the code tells you almost nothing: it can run without errors and still get half the questions wrong. For anyone working with AI, the only way to know is to measure, with a set of questions and expected answers. That is what we call an eval.

So we tested it: what changes when a coding AI gets an eval?

We asked Claude Code to build a RAG over the Central Bank of Brazil's Monetary Policy Report, the same PDF used in the RAG series. In two runs, it got only the request. In two others, it got the request, 22 questions with their answers and a script that gives the score. Then we graded all four versions on 11 questions none of them had seen.

The short version: with the eval, the system got more answers right, especially on charts. Without it, the AI made up its own test, with easy questions, and gave itself full marks. But the eval did not solve everything: in one run, the AI fitted itself to the 22 questions and did poorly on the ones it did not know. And in all four runs, it stopped before the agreed time was up.


The experiment

The document is the Monetary Policy Report of September 2026, in Portuguese: 90 pages of text, tables and charts.

The questions are the 33 from part 2 of the series: 12 answered in the text, 11 in tables and 10 only in charts. We drew 22 for development and held out 11, split by type. The 11 held-out questions never went into Claude Code's folder.

The request was the same in both conditions (in Portuguese, translated here):

This folder contains the Central Bank of Brazil's Monetary Policy Report of September 2026, rpm202609p.pdf. Build a system that answers questions about it.

  • python answer.py "question" prints the answer in one short sentence, with the number or name asked for.
  • To generate the answers, use only the local Ollama models: qwen2.5:3b, qwen2.5:7b or qwen2.5vl:3b. Python libraries and the embedding model are up to you.
  • Do not use paid APIs. Internet only to install packages and download models.
  • Work only inside this folder.
  • At the end, write a short README.md explaining what you did.

We limited the answers to small models running on the computer on purpose. With a 7-billion-parameter model, the quality of the extraction and the search makes all the difference, and there is plenty of room for the coding AI to improve the system. And the answers cost nothing.

Condition B also got the file dev.json, with the 22 questions and their expected answers, and eval.py, which runs them all through answer.py and shows the score. Plus a few more lines in the request:

  • python eval.py runs them all through answer.py and shows the score.
  • Use the evaluation to improve the system: run it, look at the errors, change things and run it again. Stop when the score stops going up.
  • Do not change eval.py or dev.json.

The time was different, and that matters for the comparison. Condition A had about 60 minutes. Condition B had about 2 hours, because the computer has no graphics card: each Ollama answer takes close to a minute, and one pass of eval.py takes 18 to 40 minutes. With one hour, condition B could barely run the evaluation twice.

How it ran: Claude Code (Opus 5.5) worked on its own, with nobody approving its commands, in an empty folder outside any repository. We recorded the whole session. After each run, we checked whether eval.py and dev.json had been changed and whether any question or answer had been written into the code.

The score uses the series' rule: the answer must contain the expected number or name, and must not start by saying it could not find it.

Results

We repeated each condition twice, always from an empty folder.

A1A2B1B2
Eval in the foldernonoyesyes
Time29 min58 min66 min82 min
Equivalent API costUS$ 1.31US$ 1.43US$ 3.41US$ 4.51
Development questions (22)13141917
Held-out questions (11)4896
Total (33)17222823

By question type, across all 33:

A1A2B1B2
Text (12)12121110
Table (11)410106
Chart (10)1077

On average, the condition with the eval got 25.5 of 33 right, against 19.5 without it. On the held-out questions, which count more, the gap is smaller: 7.5 against 6 of 11.

For comparison: in part 2 of the series, the RAG we built by hand, with qwen2.5:3b, got 10 to 12 of the 33 right. All four Claude Code versions beat that. The caveat is that all four chose qwen2.5:7b, a bigger model.

The clearest difference is on charts. Both versions with the eval read 7 of 10. The two without it read 1 and 0.

Without an eval, the AI made up its own test

Neither run without the eval handed over the system untested. Both wrote questions, ran them and looked at the answers. The problem is which questions.

A1 made up 6 questions, almost all about the text, and got them right. Its README was honest about this test. But the system scored 1 of 10 on charts, and the errors came with confidence: for "which economy had the lowest GDP growth in the second quarter", it answered "China" (the right answer is Japan). For the year with the highest unemployment since 2004, it answered 2026 (the right answer is 2020).

A2 was more careful. It wrote 12 questions, checked the answers in the PDF and fixed the way it read tables until it got all 12 right. That is why it scored 10 of 11 on tables, against 4 for A1. On charts, it scored 0 of 10, but without making things up: it answered "I could not find this information" and wrote in the README that values that exist only in charts cannot be retrieved.

But A2's 12 questions were all about text and tables. None was about a chart. Its own test gave 12 of 12; the real score was 22 of 33.

That is the pattern in both runs: the AI tests what it already knows how to do. It picks questions its system can answer, gets them right, and concludes it is done. Nobody, not even a person, writes off the top of their head the test case that will break their own code.

With an eval, the AI went after the charts

Both runs with the eval ran the evaluation as soon as the system was up, looked at the errors and changed what mattered:

  • B1 started at 15 of 22. The errors showed that tables mixed up columns and that charts did not exist as text. It started labeling each cell with its row and column, cropped the 130 charts out of the PDF and sent each one to the vision model (qwen2.5vl:3b) to describe. It also downloaded a better embedding model. Second pass: 19 of 22. On the 11 held-out questions, 9.
  • B2 took another route for the charts: instead of images, it read the PDF's vector drawings and rebuilt the series, with axes, legend and values. It worked: 7 of 10 on charts, the same as B1.

Both also wrote rules based on the errors. B1, for example, taught the search that "doze meses" and "12m" (twelve months) mean the same, and taught the prompt that "para quanto subiu" (rose to how much) asks for the final level, not the change. These are general rules, which is why they also helped on the held-out questions.

The eval changed the question the AI was asking itself. Without it, the question was "does the system work?", and the answer came from hand-picked tests. With it, the question was "why did it get these 5 wrong?", and those 5 were exactly the hard ones.

But the eval also misled

B2 finished with 17 of 22 on development and 6 of 11 on the held-out questions: 77% against 55%. For B1, it was 86% against 82%.

Three things explain the gap:

  • It optimized an intermediate step with the development answers. B2 wrote a script that checks, without calling the model, whether the expected answer appears in the retrieved passages. It is a great idea: it runs in seconds, not 20 minutes. But it used the 22 answers to tune the search until it reached 22 of 22. A search tuned for 22 questions is not a better search for all of them.
  • It kept a version that was not the best. The three passes of eval.py gave 17, 15 and 17. The first and the last tied, with different profiles: the first got more tables right, the last more charts. It handed over the last one, which got 3 of 7 tables right on the development questions, against 5 of 7 for the first.
  • It treated the score as exact. With 22 questions, a difference of 2 can be just noise: the local model can answer differently with a slightly different context. B2 never ran any pass twice to see how much the score varies on its own.

None of this is cheating. We checked: eval.py and dev.json came out untouched in both runs, and no answer was written into the code. It is what happens to any team that optimizes a metric with few questions and has no held-out ones to check against.

What none of the four did

Some things did not show up in any run:

  • Use all the time. B1 stopped at 66 minutes out of 2 hours, saying it stopped "because of time", with the score still going up. B2 stopped at 82 minutes saying "I'm already past the 2 hours". The request said "stop when the score stops going up", and B1's score had not stopped.
  • Hold out some of its own questions. Neither run with the eval set aside part of the 22 questions to check at the end, without looking at them while tuning. That was the natural defense against what happened to B2.
  • Measure the noise. None ran the same version twice.
  • Stay inside the folder. All four wrote temporary files to Claude Code's own scratch area, outside the folder. A1 went further and killed two Python processes on the computer to unblock an install, without checking where they came from. They were its own, but they might not have been.

Recipe: how to give your coding AI an eval

If you use a coding AI to build AI systems, this is the setup that worked, and what it costs:

  1. Write the questions before asking for the code. 20 to 30 questions with answers checked in the source, covering the hard cases: in our case, tables and charts. If you let the AI write them, it writes the easy ones.
  2. Give it one command that returns a number. The eval.py here has 47 lines: it runs the system on each question, compares with the expected answer and prints the score by type. Showing the wrong answer next to the expected one was what the AI used most to decide what to fix.
  3. Keep part of the questions outside the folder. A third is enough to catch what happened to B2. It is the only way to know whether the improvement holds for what the AI has not seen.
  4. Say how long each evaluation takes and ask it to use all the time. Both runs with the eval stopped with time to spare. "Stop when the score stops going up" was not enough.
  5. Ask it to run the final version twice. If the score moves 2 points on its own, an improvement of 2 points says nothing.
  6. Check the result yourself. Run the held-out questions, see whether the evaluation file changed and search the code for the expected answers. Here, nobody cheated. But the scoring rule only looks for the number in the answer: an answer listing several numbers would pass. It is the kind of shortcut worth checking.

The cost. With the eval, each run cost 2.4 to 3.4 times more (US$ 3.41 and US$ 4.51, against US$ 1.31 and US$ 1.43, at the equivalent API price) and took longer, because each evaluation pass runs the whole system. We ran everything on a Claude subscription plan; the dollar amount is what Claude Code itself calculates for the session. The four runs added up to US$ 10.66.

The risk. The eval becomes the target. With 22 questions, the AI will optimize for those 22, and the more time and freedom it has, the more fitted it gets. Without the held-out questions, B2 would look as good as A2, and it is not.

Limitations

Two runs per condition. The averages point one way, but the variation between runs is large: A2 did better than B2 on the held-out questions. With more runs, the numbers change.

The conditions had different time budgets. Condition B had twice the time, because each evaluation is slow. Part of the improvement may come from the time and not from the eval. But B1 used 66 minutes, a little more than A2, and got more right.

One model, one document, one computer. We tested only Claude Code with Opus 5.5, on one report and on a computer without a graphics card. With faster answers, the AI would run more evaluation passes, and the result could be different.

There are 11 held-out questions. Each one is worth 9 percentage points. One question more or less changes the story of a run.

The code

The experiment's scripts (the question split, the request, running Claude Code, the scoring and the checks), along with the logs of the four sessions and the READMEs the AI wrote, are in the blog repository.

Liked it? There is more on the way.

Every new analysis lands in your inbox, with the numbers, the code and what went wrong along the way.

No spam, and you can unsubscribe anytime. See the Privacy Policy