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

Forcing and Disabling Function Calls

Using tool_choice parameter to require specific functions, allow automatic selection, or disable calling entirely.

Forcing and Disabling Function Calls

You'll learn how to control whether the LLM must call a function, can choose freely, or cannot call functions at all.

The Core Idea

When working with function calling, you don't always want the LLM to decide on its own. Sometimes you need to force it to call a specific function (like always using a calculator for math). Other times you want to disable function calling entirely (like when you just want a conversational response). The tool_choice parameter gives you this control.

Three Control Modes

Think of tool_choice like setting your car's transmission:

1. Automatic (default)

tool_choice="auto"  # LLM decides whether to call functions

The LLM chooses whether to call any function based on the user's request.

2. Manual/Forced

tool_choice={"type": "function", "function": {"name": "get_weather"}}

Forces the LLM to call the specific function you name. Use this when you know a function is required.

3. Disabled

tool_choice="none"  # No function calls allowed

Prevents all function calling. The LLM responds conversationally even if functions are defined.

When to Use Each

  • auto: Normal chatbot interactions where context determines if tools are needed
  • Forced: Multi-step workflows where each step requires a specific tool
  • none: Getting explanations, summaries, or conversational responses without triggering tools

Key Takeaway: The tool_choice parameter lets you override the LLM's decision-making—forcing specific function calls when certainty is needed, or disabling them when only text responses are appropriate.