Check a Tool Call Before You Run It
Why it matters A tool call is the model asking your code to act: book, pay, delete. The model fills in the arguments from a conversation, and it can get them wrong. Running a booking for "Friday" or for twenty people at a restaurant that seats twelve is a real bug with a real cost.
The tool the model was given:
{"name": "book_table",
"input_schema": {"type": "object", "required": ["date", "time", "party_size"],
"properties": {"date": {"type": "string", "description": "YYYY-MM-DD"},
"time": {"type": "string", "description": "HH:MM, 24-hour"},
"party_size": {"type": "integer", "description": "1 to 12"}}}}
Six replies, each a pattern real models produce: a correct call; a call with "Friday" where a date was required; party_size as the string "2"; a call that left out time; a party of 20 (the description says 1 to 12, and a description is a request, not a guarantee); and no tool call at all, because the model asked the user a question first, which is often the right move.
Your job is the gate: decide whether to run the tool, send the problems back to the model so it can fix them, or pass the question to the user. (With strict: true on the tool definition the API guarantees the types and required fields, but not that the values make sense; the range and the real date are always yours to check.)
About these replies: they are simulated. Each one was written for this course in exactly the shape the Claude Messages API returns (content blocks, stop_reason, usage), and each copies something real models do. They are not recordings of a live model, so the exact wording is ours; the shapes and the problems are the real ones your code will meet.
Write gate_booking(reply). If the reply has no tool_use block, return {"action": "ask_user", "text": ...} with the joined text. Otherwise take the first book_table call and check its input: every required key present; date a real date written YYYY-MM-DD; time written HH:MM with hours 00 to 23 and minutes 00 to 59; party_size a real int (not a string, not True) from 1 to 12. Return {"action": "run", "input": ...} when all pass, else {"action": "fix", "errors": [...]} with one message per problem, each message naming the field it is about. Keep the starter's REPLIES as it is: the check reads it.
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.