Lesson 4 of 5
Does every result have to go through the model?
Module 4 explained that material in the context is not free: the model has to find what matters in it, and where usage is priced, it is paid for. Tools are the main way material arrives. This lesson takes the supplier lookup to a scale where returning everything is a problem for the task at hand, and shows a design in which code filters or calculates on the results before a selected part reaches the model. It is an option to evaluate, with conditions, not an improvement to assume.
Numbered links identify sources. Underlined terms offer a definition without leaving the lesson.
When the result is more than the task needs
Suppose the committee's approved list grows to four hundred suppliers across every category, and the organizer asks which approved fencing suppliers were added this year. Call this the expanded table; it contains the five rows from lesson 1 and, among the additions, a row for an authored supplier S-006, Weald Fences, fencing, ..., 2026-05-11. A tool that returns the whole table returns four hundred records, and in the authored harness of this lesson every one of them enters the as an observation. Module 4 gave the costs: the material occupies context whether or not it is needed, and where usage is priced by the token, it is paid for. Then the model has to do the filtering itself, reading four hundred rows to find the few that match two conditions. Whether that goes wrong depends on the task and the model; module 3 showed that a correct observation can be misread, but length alone does not establish that this particular model will make more mistakes. Nothing in this course fixes a number of rows at which the design must change. What the example fixes is a question: how much of this result does the task need, and where should the selection happen?
The first remedy is in the tool. Aizawa's tool-design account recommends that a tool accept a filter, return pages of results rather than all of them, and say when it has truncated, so that the caller asks for what it needs. 9 A find_supplier that takes a category and a date range returns the matching rows instead of four hundred. That is the design lesson 3 was building toward, and for a question the tool's author anticipated, it is enough.
Filtering and calculating in code before the model sees the result
The second remedy changes where the work happens. Instead of the harness placing each tool result in the context, the model writes a short program, the harness runs it in an , and the program calls the tools, filters or calculates on what they return, and hands back only the part worth the model's attention. Anthropic's engineering account from November 2025 describes this design for MCP tools: tool definitions are presented as code the model can discover as needed instead of all being loaded at the start, and intermediate data is processed in the execution environment so that, in its spreadsheet example, a filter for rows with a particular status runs in code and only the matching rows are logged for the model to see. 10
Here is the supplier question in that shape, as an authored illustration in plain words rather than any real product's code. The tool in this version accepts a category and nothing else, so the year has to be applied in code:
program written by the model, run by the harness:
rows = suppliers.find(category="fencing") # a tool call from inside the program;
# returns the fencing rows, 38 of the 400
recent = rows where approved_on begins with "2026"
return the id, name and approved_on of each recent row, and the count
result returned to the model:
count: 2
[ {id: S-003, name: Parkside Fencing, approved_on: 2026-01-20},
{id: S-006, name: Weald Fences, approved_on: 2026-05-11} ]
Trace what went where. The tool never returned four hundred rows; it applied the category filter and returned thirty-eight. Those thirty-eight went to the program, in the execution environment, which kept two. The model's context holds the program it wrote and the two rows that came back. The same shape carries a calculation: total the installed prices of three quotes in code and return the totals with the inputs beside them, so that the arithmetic module 3 had to redo by hand is done once, in software, with its inputs visible. Uber's engineering account from August 2026 describes doing something similar at scale in its own tools, batching sequences of tool interactions such as repeated status polling into scripts that run outside the model's context and loading tool descriptions on demand rather than all at once; the site's Intel collection summarizes the post. 11 12 Uber's figures describe Uber's environment, and the post says so; what transfers is the mechanism, which is the same one as Anthropic's example.
What the design requires, and what it does not establish
The design has conditions, and the account that proposes it names them. It needs an execution environment the harness can run code in, with limits on what that code may reach and use, and monitoring of what it does; the November 2025 account says plainly that these requirements add operational overhead and security considerations that direct tool calls avoid. 10 Module 3's three layers apply to the program the model wrote exactly as they apply to a tool call: the program runs under the environment's access, and whatever it may read or change is set by that boundary and not by the program's intentions.
It also changes what the record shows. When the model called find_supplier directly, module 3's action record held the call and its rows. Now the record holds the program and its two-row result, and the thirty-eight rows the program received are visible only if the environment logged what the program read, which is a property of the environment to check rather than assume. Fewer rows in the context is not the same as fewer rows read, and it is not privacy: the rows were read, by software the harness runs, and the question of where they went is answered by the environment's logging and the tool's data handling, not by what the model saw. Module 6 returns to that distinction.
And it does not establish that the answer is right. The program above filters on approved_on begins with "2026", which works because the table writes dates as year-month-day. Here are three programs that run without error and return the wrong rows. One filters on the year the quote was received instead of the year the supplier was approved, which answers a different question. One filters on "2025" because the model misremembered the year. And one runs against a table in which some rows were entered as day-month-year, so that the comparison silently misses them. Each returns a confident count, and none of the three counts is the answer. Code that runs is not code that is correct, which is module 7's subject. What the design does is move the work to a place where it can be checked: the program can be read, and the environment's log, where one exists, can show what it read.
The token figures in Anthropic's account describe its illustrated case, and the account says so; they are not a saving to expect from any workflow. Whether the design helps a given task depends on how much of the result the task needs, what the tool already filters, and what an environment costs to run and to audit. A task that needs the whole result in front of the model gains no reduction from filtering it, though it may still gain from batching several calls into one program. So the choice this lesson offers is between three places for the same selection: in the model's reading of a full result, in the tool through its inputs, or in code the model writes. Which is right is a judgment for the task; the supplier example at five rows needs no selection, and at four hundred the organizer has to pick one of the last two, or accept the first with its costs in view.
Carry this forward
- In the authored harness a tool result enters the context whole, occupying context and, where priced, cost, and the model then does any selection itself. Tools that accept filters, return pages and report truncation are the first remedy; no fixed number of rows makes it required.
- In the code-execution design, the model writes a program, the harness runs it in an execution environment, and the program calls tools and filters or calculates before returning a selected result. Only that result reaches the model.
- The design needs an execution environment with enforced limits and logging. Fewer rows in the context is not fewer rows read and is not privacy; the rows were read by software the harness runs, and whether that was logged is a property of the environment.
- Code that runs is not code that is correct: a filter on the wrong field, the wrong year or an inconsistent date format runs and returns the wrong rows. The design moves work to where it can be read and logged; the result still has to be checked.
Lesson check
Choose an answer for each question.
This is a practice check. Answers reset when you leave this page. Results are not saved and do not place you in another module or award a qualification.
You have now seen a tool's routes, its neighbours, its results and errors, and where its results can be processed. The last lesson writes all of that down as a contract, with the line that decides what the tool may touch.
Sources · Reviewed 2026-09-29
- 9. Anthropic engineering (Ken Aizawa, 11 September 2025): Writing effective tools for agents, with agents
- 10. Anthropic engineering (4 November 2025): Code execution with MCP
- 11. Uber Engineering (Uday Kiran Medisetty, 27 August 2026): Running a software factory efficiently at Uber scale
- 12. VibeLeaderboard Intel: How Uber measures and cuts the cost of agent-written code
Sources support nearby explanations. Product details can change. Scenarios and model results are authored illustrations unless a lesson explicitly identifies a recorded execution. Module 7 identifies its offline code checks.