Sub topic 1
Built-in tools versus function tools
Prerequisites
This chapter assumes you can:
- Write basic Python or JavaScript.
- Call an LLM chat or responses API with an API key.
- Read JSON request and response bodies.
- Explain the basic idea of tool (function) calling.
Two kinds of tools
A tool is a capability you let the model request during a conversation. Providers offer two kinds, and the difference is who runs the tool.
- A function tool is one you define. You describe its name and parameters in a JSON schema. The model asks for a call, and your code runs it and sends back the result.
- A built-in tool is hosted by the provider. You turn it on by naming it in the request. The provider runs it on its own servers and puts the result into the model's answer.
Web search, code execution, and file search are built-in tools. Your own database lookup or internal API call is a function tool.
Who runs the tool
With a function tool, your application sits inside the loop. Each tool call costs you a network round trip and some code.
With a built-in tool, the loop happens on the provider's side. You send one request and get one response that already contains the tool results.
What the declarations look like
Both kinds go in the same tools list. A built-in tool is usually a short entry with a type name.
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-4.1",
tools=[{"type": "web_search"}],
input="What are the most recent stable releases of Python?",
)
print(response.output_text)Nothing else is needed. You write no schema and no handler, and the provider runs the search.
Comparing them
| Aspect | Built-in tool | Function tool |
|---|---|---|
| Who runs it | The provider | Your code |
| Setup | Name the tool in the request | Write a schema and a handler |
| Round trips | One request | One extra request per call |
| Control | Limited to the options offered | Complete |
| Data location | Inputs go to the provider's tool | Stays in your systems if you want |
Common mistakes
- Expecting a handler to fire. Built-in tool calls never reach your code, so you cannot intercept or edit them. You can only inspect them afterward in the response.
- Assuming every provider offers the same tools. Names, options, and availability differ by provider and model.
- Using a built-in tool for private logic. If the work needs your own systems or strict control over data, write a function tool.
Exercise
Your app must look up a customer's order status in a private database, and it must also answer questions about current news. Which tool type fits each task, and why?
Show answer
Use a function tool for the order lookup, because the data lives in your own system and your code must run the query. Use the built-in web search tool for current news, because the provider runs the search and returns results in the same response, so you write no handler.