Don't Trust the Arguments
validating tool calls
Part of: Tool-Using Agent
The loop works when everything goes right. It doesn't yet handle a model that asks for a tool that doesn't exist, or hands you an argument that's missing or the wrong type. Models are usually good at following a schema, but "usually" is not a word you want near code that runs eval(). This lesson hardens execute tool before it runs anything. Three ways a tool call can be bad 1. Unknown tool name. The model, or a bug, or a model update, asks for a tool you never registered. 2. Missing required argument. input schema said required: ["expression"], but the block's input dict has no such key. 3. Wrong type. The schema said "type": "integer" for days, and you got the string "three". None of these should crash your program, and none should silently do the wrong thing. Each turns into a short, clear error message you send back as the tool result, so the model can notice and correct itself on the next turn. That result string, error message and all, goes back through the normal tool result message. The model reads "error: missing required argument 'city'" the same way it reads "Sunny, 24C". It is text either way, and a well-behaved model apologizes, fixes its input, and tries again. Never e
Challenge: Guard the Tool Call