0Pricing
Learn AI with Python · Lesson

Function Calling and Tool Use with LLMs

Defining tools as JSON schema, handling tool_calls in response, executing and returning results.

What is Function Calling?

Function calling (also called tool use) lets an LLM request that your code run a function. The model does not execute anything itself, it returns a structured request saying "call this function with these arguments". Your program runs it and feeds the result back.

This is how LLMs fetch live data, do math, or trigger real actions.

Describing a Tool

You give the model a list of tools. Each tool has a name, a description, and parameters defined as a JSON Schema. The description is critical, the model uses it to decide when the tool applies.

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get current weather for a city",
        "parameters": {
            "type": "object",
            "properties": {
                "city": {"type": "string", "description": "City name"}
            },
            "required": ["city"]
        }
    }
}]

All lessons in this course

  1. OpenAI API: chat.completions and Streaming
  2. Anthropic Claude API in Python
  3. Function Calling and Tool Use with LLMs
  4. Prompt Engineering for Production LLM Apps
← Back to Learn AI with Python