Structured Output and Tool Calling · Tool Calling · lesson 4 of 6
Defining a tool
about 16 minutes · free · runs in your browser
A function, described in JSON
Tool calling inverts the conversation. Instead of asking the model for text, you hand it a list of functions it may call, and it answers with which one, and with what arguments. Your code runs it. The model never touches your data — it only asks.
A tool is a JSON description of a function:
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Look up the current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}
The description is not documentation, it is the prompt. It is the only thing the model
reads when deciding whether this tool is the right one, and a vague description is the
whole reason a model "ignores" a tool it should have used.
Your turn: write tool_spec(name, description, params) that builds this structure,
where params maps a parameter name to a JSON type string. Every parameter is required.
You start from this, and edit it in the browser:
import fake_llm
def tool_spec(name, description, params):
"""Build a tool definition. params maps a name to a JSON type string."""
return {}