Lesson 02.09 · Phase 02 · Tool Use & Function Calling

Tool results that fit the context

A tool's result is part of the prompt. Return the fields, the rows and the computation the answer needs, not everything you have, and the model gets cheaper and more accurate at once.

Learning objectives

  • Shape a search tool's results: select fields, paginate with a total and a cursor, use a compact table, and filter and sort in the tool.
  • Measure the real token cost of each shape, and a model's accuracy with it.
  • Explain why smaller results are often more accurate, not just cheaper.
  • Avoid the traps of shaping: dropped units, partial pages read as complete, and lucky passes.

The easy way to write a search tool is to return what the database returns: every match, every field, pretty-printed. For 40 kettles in this lesson's catalogue that's 33,000 characters, about 9,200 real tokens, re-sent on every later step of the run (Phase 3 · Lesson 11). And it doesn't even help: asked for the cheapest in-stock kettle, llama3.2 read that wall of JSON and named the wrong one.

Loading the full lesson…