How do you test a tool without calling a model?

L1 · FundamentalsConcept~6 minTool use

Your team tests the agent only end to end: send a prompt, see if the answer looks right. It's slow, flaky and expensive, and when it fails nobody knows whether the tool or the model is at fault. How would you test tools?

Answer it out loud or on paper first. Then open the short answer.

Short answer

Tools are ordinary functions with an unusual caller, so test them like functions, with no model. Unit-test behaviour, including the arguments a model might send: missing fields, wrong types, unknown ids, huge inputs, injection strings. Test that errors come back as useful text, not exceptions. Test the schema (the definition the model sees matches what the function accepts). Use fakes for external APIs, including slow and failing ones. Keep a smaller set of end-to-end evals for the model's choices. Then a failure tells you which layer broke.

Full answer

Layers

LayerTestsModel?
Tool functionCorrect results, edge cases, errors as text, limits enforcedNo
Schema contractDefinition matches the signature; required fields; enumsNo
DispatcherUnknown tool, invalid JSON, timeouts, size caps, call idsNo (scripted model messages)
Agent loopStop conditions, budgets, recoveryScripted model
Model behaviourTool choice and arguments on real requestsYes, as evals

Model-shaped inputs

Models send things humans don't: "amount": "49.00" as a string, null for optional fields, an id from another tenant, a 10,000-character query. Write tests for those.

Fakes, not mocks of everything

A fake payments API with modes ("normal", "slow", "fails after commit") lets you test retries and idempotency deterministically.

Scripted models

For loop tests, a function that replays fixed assistant messages makes runs deterministic and free. This course's lessons all run this way offline.

Follow-ups

  1. L2. How do you catch a schema drifting from the code?

    Expected answer

    Generate the schema from the function signature or types, or test that a schema-valid example call succeeds and an invalid one is rejected.

  2. L2. What belongs in evals rather than tests?

    Expected answer

    Whether the model picks the right tool and arguments for realistic requests; that's probabilistic and measured as a rate.

  3. L3. How do you keep end-to-end evals from being flaky?

    Expected answer

    Multiple runs per case with pass rates, judges based on side effects and state, pinned model versions, and stable fixtures.

Wrong answers interviewers hear
  • "You can't test agent tools without the model." Tools are functions; most of their behaviour is deterministic.
  • "End-to-end tests cover everything." They're slow, costly and don't localise failures.
  • "Mock the model to always call the tool correctly." Then you never test the bad arguments models really send.

Taught in

Improve this answer