Skip to content
mentoor

Topic 3 of 6 · 5 min read

Checking tool calls and their arguments

Goal: Write assertions on recorded tool calls that catch a wrong tool, a bad argument or an ignored tool error.

Record every tool call an agent makes and write assertions on them, the way you would assert on mocked calls in a unit test.

Check yourself · 1 of 3

An agent is asked to email one customer. Which assertion best catches a wrong recipient?

Choose one answer

Why it matters

Agents act through tools: search, run a query, send an email, edit a file. Most agent bugs show up as a bad call. The agent picks delete_record instead of archive_record, passes a customer id from the wrong conversation, or receives {"error": "rate limited"} and reports success anyway. Final answers can hide all of these.

How to do it

  1. Capture calls. Wrap each tool so it appends {name, args, result, error} to a list for the run.
  2. Assert the right tool. For the task "find the order status", the agent should call a read tool, not a write tool.
  3. Assert the arguments. Check exact values for ids and amounts, and patterns for free text. Do not require the same wording every time.
  4. Assert what must not happen. No call to a destructive tool, no call for a user other than the one in the task, no more than one email.
  5. Assert error handling. When a tool returned an error, the next step must retry sensibly, ask the user or report the failure. It must not claim success.
  6. Use tolerant matching. Compare parsed values, such as a date, not the raw string.

Before and after

# Weak: only checks that something was called
assert any(c.name == "send_email" for c in run.calls)
# Better: checks the call, its arguments and the count
emails = [c for c in run.calls if c.name == "send_email"]
assert len(emails) == 1
assert emails[0].args["to"] == task.customer_email
assert "refund" in emails[0].args["body"].lower()
assert not any(c.name == "delete_record" for c in run.calls)

The weak version passes if the agent emails the wrong person three times.

What goes wrong

  • Exact string matching. Free-text arguments vary between runs, so exact matches create false failures.
  • Missing negative checks. Tests that only look for required calls miss extra harmful ones.
  • Ignoring tool errors. An agent that proceeds after an error is often the most dangerous kind.
  • Vague tool descriptions. Wrong tool choices are often a fault in the tool description, not the model.

Examples

The wrong customer

A task says to email customer A. The recorded call has to set to customer B's address. A test that only checks that send_email was called passes. An assertion on the argument fails it.

Success after an error

update_order returns {"error": "conflict"} and the agent replies "Order updated." The assertion: if the last call to update_order has an error, the final message must not claim success.

Key points

  • Wrap tools so every call, argument, result and error is recorded.
  • Assert the tool name, the exact ids and amounts, and the number of calls.
  • Add negative assertions: calls that must not happen, such as destructive tools.
  • Check that tool errors lead to a retry, a question or an honest failure report.
  • Compare structured values, not raw strings, so correct runs are not failed.

Common mistakes

  • Asserting only that a tool was called, not with which arguments.
  • Matching free-text arguments character for character.
  • Never checking that dangerous tools were not called.
  • Blaming the model for tool errors that a clearer tool description would prevent.

Check yourself · 2 of 3

A tool returns an error and the agent tells the user the task succeeded. What should the eval check?

Choose one answer

Check yourself · 3 of 3

Why are negative assertions, such as "no delete call", important in agent evals?

Choose one answer

Practice items, not counted towards your mastery.

Start here