Claude API · Tools and structured output
Define a tool by hand
A tool has a name, a description and a JSON Schema for its input. Claude replies with a tool_use block when it wants to call it.
tools = [{
"name": "get_weather",
"description": "Get the current weather for a city.",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
}]
Official Claude API documentation
More tools and structured output commands
- Let the SDK run the tool loop
- Return a tool result
- Guarantee valid tool input
- Get a validated Python object back
- Constrain output with a JSON Schema
All tools and structured output commands · Claude API cheatsheet