Agents, MCP and skillsLoading progress…

Errors and observations

Trace a model-requested tool call through schema validation, execution and a returned observation.

Errors and observations

What the tool returns is the model's only view of what happened, an observation. When something fails, return it in a defined, flagged form so the next step can recover or stop honestly. Tell failures apart: a domain error (the tool ran and said no), a transport failure (it could not be reached, so a retry may help) and invalid arguments (fix the call). Hiding a failure, or answering with an invented success, lets later steps build on a fiction.

failure:
tool result (host side): is_error = true, content = "no data for Atlantis" what the model is shown: { is_error: true, content: "no data for Atlantis" } sensible next step: tell the user the lookup failed; retrying will not help

Distinguish a tool's own refusal (domain), an unreachable service (transport) and a malformed request (invalid). The model needs the error in a defined, flagged form to recover or stop honestly.

Pick a failure and turn error reporting on and off.

Predict first. Should a failed lookup be silently returned as an invented successful result?

Chapter context

A tool call is a structured request for the application to perform an operation. The model proposes arguments; the surrounding application decides whether the operation is valid and permitted and is responsible for executing it.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

A useful execution model is: requested operation + validated arguments + permission decision → execution result. Schema validation establishes a data-shape contract; authorization establishes whether this caller may perform this operation. Neither implies the other.

Worked example

A calculator tool requires numeric a and b and returns a+b. For a=2,b=3, its result is 5. If the request instead asks for an unknown field or omits b, reject or repair the request according to the contract before executing. A retry of this pure calculation is harmless; that does not establish the same property for a side-effecting tool.

Reference code

The following example uses the Python standard library and does not call a remote service.

def add(a,b):
    if type(a) not in (int,float) or type(b) not in (int,float):
        raise ValueError('numeric inputs required')
    return a+b
assert add(2,3) == 5
try:
    add('2',3)
except ValueError:
    pass
else:
    raise AssertionError('invalid input accepted')

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

A model proposal is not permission. JSON schema shape validation is not business-rule validation. Tool outputs must not silently become trusted instructions.