A tool definition is an operational contract between an LLM and the code that executes its actions. Its name, purpose, and argument schema help the model decide when and how to invoke the tool. The definition enters the context window; a tool call and its execution output can then add further context. section 4.2.1 section 1.5.3
A robust definition specifies:
- A unique, stable name and a description that states when, why, and under what conditions to use the tool. section 4.2.1
- A strictly typed parameter schema with clear field names and explicit constraints. section 4.2.1
- The expected output structure and actionable error responses that help the agent recover from invalid arguments. section 4.2.1
Keep the definition distinct from the tool call—the structured request the model emits—and from the output returned after execution. Definitions guide selection and argument formation; calls and outputs usually join the working context, while only relevant outputs may later be persisted as memory. section 1.5.3
Weather lookup
A function definition can name get_weather, describe its purpose, and require a location string. The model requests the function; code executes it and returns the weather value to the context for the final response. section 4.6.1
Listing 4.1 Python script using an OpenAI model and a mock weather tool
from openai import OpenAI
import json
client = OpenAI()
TOOLS = [{ #1
"type": "function",
"name": "get_weather", #2
"description": "Get the current weather in a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City or place name"
}
},
"required": ["location"]
}
}]
def query_model(prompt, model="gpt-4o-mini"):
response = client.responses.create( #3
model=model,
input=prompt,
tools=TOOLS,
tool_choice="required",
)
input_items = list(response.output)
for item in response.output: #4
if item.type != "function_call":
continue
function_name = item.name
function_args = json.loads(item.arguments)
result = route_function_call(function_name, function_args) #5
input_items.append({
"type": "function_call_output",
"call_id": item.call_id,
"output": json.dumps(result),
})
final_response = client.responses.create( #6
model=model,
input=input_items,
tools=TOOLS,
)
return final_response.output_text
Inspect the Python example to see a function schema passed to the OpenAI API and the requested function executed in an agent loop. section 4.6.1



