Filtering test logs before a coding agent sees them cut input tokens by 94.1%
A dev.to benchmark found that handing an AI coding agent a short list of failures, instead of a full pytest log, cut input tokens, cost and time.
The short version
- Raw pytest output was 60,749 characters on the first run; the filtered JSON summary was 1,506.
- Cumulative input tokens dropped from 92,385 to 5,445, a 94.1% cut.
- Estimated cost fell from $0.0770 to $0.0100, and run time from 25.94 to 16.88 seconds.
- The filtered agent fixed all three modules in one edit turn; the raw-log agent needed an extra round.
- Both setups scored 20 out of 20 on the hidden grading suite.
Why it matters
If you use or pay for AI coding tools, wasted input is a direct cost and a source of distraction. This test suggests that trimming what the agent reads can save money and time without hurting results. The figures come from one author's own test, so treat them as a strong hint, not a guarantee.
The hidden cost of a test log
As dev.to reported, a developer running a series of coding-agent benchmarks found that one of the biggest sources of wasted tokens is not the code. It is the output of the test runner. A token is the small chunk of text an AI model reads and is billed for, so more text in means a higher bill.
In the experiment, the test suite had 80 tests across three modules of a payment settlement program. Seventy-six passed and four failed. A standard pytest run (pytest is a common Python testing tool) printed all of it: color codes, environment banners, a line for every passing test, debug text and long tracebacks, which are step-by-step records of where an error happened.
That first run produced 60,749 characters. The author estimates a single run like this adds more than 28,000 tokens to the agent's conversation.
Two setups, one task
The author compared two ways of wiring the same agent to the same tests. The model was gemini-3.8-flash with its thinking level set to low, and it ran inside an isolated virtual machine with no network cards. Each setup was then graded on a hidden suite of 20 cases.
In the first setup, the raw terminal output went straight into the conversation. In the second, a small program sat between the agent and the test runner. It stripped the color codes, the banners, all 76 passing tests and the internal framework steps, then returned a short summary in JSON, a simple structured text format.
That summary was 1,506 characters. It gave the totals (80 run, 76 passed, 4 failed) and, for each failure, the test name, file, line number and a description of what was expected.
How the raw log snowballed
The trace shows why the raw approach got expensive. Every tool result stays in the conversation, so each new turn re-reads everything that came before. The first call used 2,406 input tokens. By the second, after the 60,749-character log was added, input jumped to 31,170.
According to the write-up, the agent was distracted by the wall of text and patched only one of the three files. That triggered a second test run, which added another 56,544 characters. The third turn then needed 58,809 input tokens, and the cumulative input total reached 92,385.
With the filtered summary, the agent saw all four failures at once. It fixed all three files in a single edit turn, which needed 3,030 input tokens. The whole job took two model calls instead of three.
The numbers side by side
- Cumulative input tokens: 92,385 down to 5,445, a 94.1% cut.
- Estimated cost: $0.0770 down to $0.0100, a drop of 87.0%.
- Elapsed time: 25.94 seconds down to 16.88 seconds, 35.0% less.
- Output tokens: 2,068 down to 1,571, a 24.0% reduction.
- Hidden test score: 20 out of 20 in both setups.
The last line matters most. The filtered agent was not cheaper because it did less or got worse results. Both finished the job correctly. It was cheaper because it avoided reading text it did not need.
What to take from it, and what to doubt
The author's advice is simple: do not pipe raw test output into an agent. Use pytest's quieter options or a JSON reporter plugin, remove color codes and passing tests, and pass along only the failure details plus a pass count. The author also points to a tool called rtk (Rust Token Killer), or a short Python wrapper, and claims savings of 85% to 95%.
Keep the limits in mind. The write-up describes one run, one model and one small, purpose-built project, run by the author. It is not an independent study, and your results will depend on how noisy your own test output is. A project with few passing tests and short logs will save much less.
Still, the logic holds up in plain terms. An assistant given a short, clear list of what is broken has less to wade through than one given a long transcript where the problems are buried.
What to watch
- Will other people reproduce the savings on larger, messier codebases and with different models?
- Do coding agents start filtering test output by default, instead of leaving it to each developer?
Try it
If you run an AI coding agent on a Python project, check what its test tool returns. Try running pytest with --tb=short -q --no-header --no-summary, or add pytest-json-report, and compare the output size.
Sources and links
- Reportingdev.to: the article we sourced
Liked it? Say why
Add a line for other readers.
No account needed. We never show your email. Comments with links, ads or abuse are held and not shown. Your comment shows after a quick check.
Listen to the AI Wire headlines
Listen to the AI WireListen to our daily AI shows every morning: on your commute, in the shower, wherever you are
Listen to the daily showsFirst reported by dev.to · Read the original. Written by the SI Agent News Desk from the reporting above.Written with AI from the source above. Every number is checked against the source. Spot a mistake? Corrections.
