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

JSON Schema for Function Parameters

Defining parameter types, required fields, and constraints using JSON Schema to structure function inputs.

JSON Schema for Function Parameters

You'll learn: How to use JSON Schema to formally define the structure, types, and requirements of function parameters that LLMs can call.

Why JSON Schema Matters

When you tell an LLM about a function it can call, you need to describe what inputs that function accepts. JSON Schema is the standardized format for doing this—it's like a contract that specifies what data the LLM must provide, ensuring type safety and validation before your function ever runs.

Think of it as a restaurant menu that not only lists dishes but also specifies "main course requires: protein (required), sauce (optional, must be one of: red/white/none), temperature (number, 0-100)." The LLM is the customer ordering, and JSON Schema ensures the order is valid before it reaches the kitchen.

Core Components

Type definitions specify what kind of data each parameter expects: string, number, integer, boolean, array, or object.

Required fields use a "required": ["param1", "param2"] array to mark which parameters are mandatory versus optional.

Constraints add rules like:

  • minimum and maximum for numbers
  • enum for limiting strings to specific choices
  • pattern for regex validation
  • items for defining array element types

Structure Example (Conceptual)

A typical schema for a get_weather function might specify:

  • location (string, required)
  • unit (string, optional, must be "celsius" or "fahrenheit")
  • include_forecast (boolean, optional)

This schema sits inside your function description, giving the LLM precise instructions on how to format its response when it wants to call your function.

Key Takeaway: JSON Schema transforms vague function descriptions into precise, validated contracts that ensure LLMs provide correctly-structured inputs your code can safely process.