Frodex

Frodex

Beta
EnglishPortuguês (BR)
Foundations
1Introduction2Tokens3Controlling the Model
Communicating with LLMs
4Anatomy of a Good Prompt5System Prompts and Personas6Few-Shot Learning
Structured Outputs
7JSON Mode and Structured Output8Function Calling
Advanced Techniques
9Chain of Thought Reasoning10Managing the Context Window11Embeddings and Semantic Search
Production Systems
12Retrieval-Augmented Generation (RAG)13Streaming Responses14Evaluation and Cost Optimization
Frodex

Frodex

Beta
EnglishPortuguês (BR)
Foundations
1Introduction2Tokens3Controlling the Model
Communicating with LLMs
4Anatomy of a Good Prompt5System Prompts and Personas6Few-Shot Learning
Structured Outputs
7JSON Mode and Structured Output8Function Calling
Advanced Techniques
9Chain of Thought Reasoning10Managing the Context Window11Embeddings and Semantic Search
Production Systems
12Retrieval-Augmented Generation (RAG)13Streaming Responses14Evaluation and Cost Optimization
Structured Outputs
20 minLesson 8 of 14

Function Calling

Enable LLMs to interact with external systems in a controlled, production-ready way

Learning goals

  • •Understand function calling and tool use
  • •Learn to define function schemas
  • •Implement safe and effective function execution

What Is Function Calling?

Function calling allows LLMs to:

  1. Recognize when a function should be called
  2. Extract the correct parameters from natural language
  3. Return a structured function call for your code to execute

The model doesn't execute functions—it tells your code what to call.

Defining Functions

Functions are defined using JSON Schema:

const functions = [{
  name: "get_weather",
  description: "Get the current weather for a location",
  parameters: {
    type: "object",
    properties: {
      location: {
        type: "string",
        description: "City and state, e.g., 'San Francisco, CA'"
      },
      unit: {
        type: "string",
        enum: ["celsius", "fahrenheit"],
        description: "Temperature unit"
      }
    },
    required: ["location"]
  }
}];

Clear descriptions help the model choose correctly.

The Function Calling Loop

The typical pattern:

  1. User sends a message
  2. Model decides to call a function
  3. Your code executes the function
  4. Send the result back to the model
  5. Model generates a final response
User: "What's the weather in Tokyo?"
↓
Model: {function: "get_weather", arguments: {location: "Tokyo, Japan"}}
↓
Your code: fetch weather API → {temp: 22, condition: "sunny"}
↓
Model: "It's currently 22°C and sunny in Tokyo."

Common mistakes

×Poor function descriptions—the model relies on descriptions to choose functions
×Missing parameter descriptions—leads to incorrect parameter extraction
×Not handling function errors—always have fallback behavior for failed calls
×Trusting function calls blindly—validate parameters before executing

Key takeaways

+Function calling bridges natural language and structured API calls
+Clear function and parameter descriptions are critical for accuracy
+Always validate parameters before executing functions
+The model suggests calls—your code executes them safely

Playground

Try These Experiments

Prompt

Why This Experiment?

See how function calling extracts structured parameters from natural language.

Response
No response yet
Choose an experiment above or type your own prompt, then click Run to see the model's response here.

The model extracts parameters from natural language: query='running shoes', max_price=100.