Declaring tools and reading tool_use blocks
Tool use lets Claude call functions you define, rather than only ever generating text. You declare tools as a top-level tools array on the request, where each tool has a name, a natural-language description, and an input_schema — a JSON Schema describing the parameters the tool accepts. The description matters more than developers usually expect: Claude decides both whether to call a tool and how to fill its arguments almost entirely from that description, so a vague one produces unreliable calls no matter how good the underlying function is.
When Claude decides a tool is needed, it doesn't call anything itself — it returns a response with stop_reason 'tool_use' and a tool_use content block containing the tool's name, a unique id, and an input object matching your schema. Your application code is responsible for actually executing the corresponding function with those arguments; Claude never reaches out and runs code on its own. This client-executes-the-tool model is what makes tool use safe to use with arbitrary functions — nothing runs without your code choosing to run it.
