AI agents and MCP

Stage 2 · Lesson 5 of 7

Tool errors the model can recover from

Tool calling from scratch

Tools fail: an order is not found, an API times out, an argument is invalid. Do not let the exception crash the loop. Return a tool result marked as an error, with Anthropic's is_error flag or a clear error field, and a short message that says what went wrong and what to try instead.

For example: 'No order found for that email. Ask the customer for the order number, which starts with ORD-.' A good error lets the model retry with fixed arguments, choose another tool or ask the user, which is most of what makes an feel robust. Log the full technical error for yourself separately.

Common trapreturning an empty result on failure, so the model concludes the customer has no orders and says so confidently.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • GuideFree
    Claude Tool Use Documentation

    Anthropic · Intermediate

    Read Overview, Define tools and Handle tool calls, then follow the tutorial that grows one call into a full loop

  • GuideFree
    OpenAI Function Calling Guide

    OpenAI · Intermediate

    The same loop on the Responses API: read it after your first provider to see what is universal

Practise

  • Free notebooks: work through the tool use course, which builds tools and a loop exercise by exercise

  • Runnable function-calling examples to compare with your own loop

Keep handy

Also worth your time

Mark this stage as not done?