Course contentsShow
← AI Engineering
Lesson 568 of 1,88614. Function Calling and Tool UseFree lesson

Handling Tool Call Results

Formatting and injecting function results back into the conversation for the next LLM turn.

Handling Tool Call Results

What you'll learn: How to properly format function execution results and feed them back to the LLM so it can complete its response.

The Missing Link in the Conversation

When an LLM calls a function (like get_weather("London")), it pauses and waits for you to actually run that function. But here's the critical part: the LLM has no idea what happened until you tell it. Handling tool call results means taking the output from your executed function and injecting it back into the conversation in a format the LLM understands.

Think of it like a phone call where someone asks you to check something. They wait silently while you look it up, then you come back and say "Okay, I found it—here's what I got." Without that return step, the conversation is stuck.

The Injection Pattern

After executing a function, you must:

  1. Format the result as a string or JSON structure
  2. Create a tool response message with the tool_call_id that matches the original request
  3. Append it to the conversation history before making the next LLM request

The LLM sent you a tool_call_id in its function call response—this is your tracking token. Your tool result message must reference this exact ID so the LLM knows which call you're responding to.

Why This Matters

Without proper result handling, the LLM can't:

  • Complete its thought process
  • Synthesize information from multiple tools
  • Provide accurate answers based on real data

The result message bridges the gap between the LLM's world (tokens and text) and your world (actual computation and data).

Key Takeaway: Tool call results must be formatted with the matching tool_call_id and injected back into the conversation history as a special message type, allowing the LLM to continue reasoning with real execution data.