Skip to content
Back to log

How does LLM tool use work?

Chainabit's Chao · · 7 min read

In short

Explore the function calling workflow, its fields, and its limitations, from the model generating a tool call to the application sending back the result.

What does a tool call do?

OpenAI uses function calling, also known as tool calling, to let models interact with external systems and access data outside their training data. In an API request, the application can send a list of available tools along with the user’s prompt. The model may decide that completing the task requires data or functionality provided by one of those tools.

For example, one tool available to the model might retrieve weather information for a location. Another might look up account details using a user ID or initiate a refund for a missing order. In OpenAI’s terminology, a function is a specific type of tool defined using JSON Schema. The function definition gives the model a way to pass data to the application. The application code can then use that data to retrieve information or perform an action the model suggests.

A tool call is a special response generated by the model. In OpenAI’s weather example, the model can answer a prompt about the weather in Paris by calling get_weather. In that call, Paris is the value of the location argument. The tool then uses the input from the call to produce a result. The call in the model’s initial response and the result produced by the tool are separate parts of the workflow.

The function calling workflow

OpenAI describes tool use as a multi-step conversation between the application and the model. In the first request, the application supplies the tools the model can call. If the model returns a tool call, the application uses the input from the call to run its own code. It then sends a second request containing the tool output. The model can respond with a final answer or make further tool calls.

In the weather example, the first request includes the tool definition and the user’s question. The model’s call contains the tool name and the location argument. After using that input to get the result, the application sends the tool definition, the original prompt, the model’s call, and the tool output back to the model. The model can then use that information to give the user a text response.

Tool output is tied to a specific call made by the model. OpenAI’s examples use call_id to make that connection. The output can be structured JSON or plain text. In the weather example, the JSON object contains fields for the temperature and its unit. Images or file contents can also be passed as tool output. The model can use the content produced by the tool in its next response.

Anthropic also describes a round trip for tools defined by the application. Claude decides when to call a tool based on the user’s request and the tool description. When it calls a tool that runs in the application, the response includes a tool_use block. The application performs the operation and returns the result in a tool_result block. Claude can then use that result to answer the original question.

Anthropic distinguishes tools by where their code runs. User-defined client tools run in the application. For these tools, Claude returns stop_reason: "tool_use" and one or more tool_use blocks. Server tools run on Anthropic’s infrastructure. For some client tools whose schemas Anthropic publishes, the application still executes the call and returns a tool_result.

In Anthropic’s client tool example, the first request defines the get_weather tool. The tool’s input_schema field contains an object and marks the location field as required. The tool_use block in Claude’s response contains the tool name and input. In the second request, the tool_use_id in tool_result links the result to the ID of the original call.

Fields in a function definition

According to OpenAI, function definitions are typically declared in the tools parameter of each API request. The type field in the definition is set to function. The name field gives the function’s name, and description explains when and how to use it. The JSON Schema in parameters defines the function’s input arguments. The strict field specifies whether strict mode applies to the function call.

In OpenAI’s get_weather definition, parameters is defined as an object. The properties field contains location and units, both declared as string. For units, the enum lists celsius and fahrenheit as possible values. The definition’s required list includes both fields, and additionalProperties is set to false.

Turn this insight into action.

Use the mobile app to continue with guided workflows.

Alongside field types and enum values, JSON Schema can describe fields and define nested and recursive objects. Custom tools are available alongside function tools. OpenAI describes custom tools as working with free-form text inputs and outputs. The platform’s built-in tools include web search, code execution, and access to functionality from an MCP server.

According to OpenAI, function definitions are inserted into the system message using a syntax the model was trained on. Callable function definitions count toward the model’s context limit. With tool search, the application can load deferred functions later in the interaction. These functions use the same schema format.

Handling the call and sending back the result

In OpenAI’s Responses API workflow, the response’s output array can include items whose type is function_call. Each function call item contains a call_id, a name, and JSON-encoded arguments. The application uses the name and arguments to run the corresponding function code. A model response can contain zero, one, or multiple calls.

To send back the result, OpenAI’s example uses an item of type function_call_output. The item’s call_id matches the result to the corresponding function call, and output contains the function result. Once the results have been added to the messages, they can be sent to the model. The model can use the tool output to produce a final answer or make further calls.

The result in function_call_output is typically a string. OpenAI says that this string can contain JSON, an error code, or plain text. For functions that return images or files, the application can send an array of image or file objects in place of a string. For a function with no return value, a string can indicate success or failure.

OpenAI says that reasoning items returned by reasoning models alongside tool calls must also be sent back with the tool outputs. These items are separate from the function_call_output item the application adds to carry the function result. The Responses API workflow can continue with any further tool calls the task requires.

Configuring tool selection

By default, OpenAI’s model decides when to use tools and how many to use. The tool_choice parameter can change this behavior. Setting it to auto allows zero, one, or multiple function calls. Setting it to required requires one or more function calls. You can also select a specific function to make the model call that exact function.

The allowed_tools option limits the model’s calls to a subset of the tools it has been given. Setting tool_choice to none makes the model behave as though no functions were supplied. The model can also choose to call multiple functions in a single turn. Setting parallel_tool_calls to false limits it to zero or one call.

With Anthropic’s default tool_choice of auto, Claude decides on each turn whether to call a tool or respond directly. According to Anthropic, Claude calls a tool when the capability described in the tool matches the request and the answer is missing from the context. It can respond directly to questions about stable facts, creative tasks, and conversational exchanges.

Schema compliance and limits

In OpenAI’s API, strict: true ensures that function calls conform to the function schema. For this to work, every object in parameters must set additionalProperties to false, and every field in properties must be marked as required. An optional field can be represented by including null among its allowed types. If a schema sent with strict: true fails to meet these conditions, the API rejects the request and returns details about the missing constraints.

Strict mode supports only a subset of JSON Schema features. When strict is omitted, the behavior depends on the API. According to OpenAI, Responses requests try to adapt the schema to strict mode where possible. If the schema cannot be adapted, the API falls back to non-strict function calling. In that case, the tool information in the response shows strict: false. Chat Completions requests use non-strict mode by default.

Anthropic says that when the prompt lacks the information needed to fill in required parameters, the model may ask for the missing information or infer a value. For example, if a weather tool requires location and the user supplies none, the model may guess a location. Anthropic also notes that this behavior can vary.

Ready to start?

Download the app and continue from your phone.

End of Entry