liveBook · Manning

JSON Schema

As explained in Build an AI Agent (From Scratch)

JSON Schema is a standard for describing and validating the structure, types, allowed values, and required fields of JSON data.

JSON Schema describes the inputs a tool expects, giving an LLM a structured contract for selecting and calling that tool. A schema can define an object, property types, allowed values, and required fields. section 3.2.1

A calculator schema illustrates the main building blocks:

  • Use type object for the parameter set. section 3.2.1
  • Declare properties such as operator, first_number, and second_number. section 3.2.1
  • Restrict operator with an enum containing add, subtract, multiply, and divide. section 3.2.1
  • Mark every necessary input in required so the generated call includes it. section 3.2.1

Calculator tool call

For “What is 1234 x 5678?”, the model emits a call with operator multiply and the two numeric operands. The application parses those arguments, runs calculator(), and returns 7,006,652 to the model for its final answer. section 3.2.1

Listing 3.1 Calculator tool definition schema
calculator_tool_definition = { 
    "type": "function",
    "function": {
        "name": "calculator", 
        "description": "Perform basic arithmetic operations.",
        "parameters": {
            "type": "object",
            "properties": {
                "operator": {
                    "type": "string",
                    "description": "Arithmetic operation to perform",
                    "enum": ["add", "subtract", "multiply", "divide"]
                },
                "first_number": {
                    "type": "number",
                    "description": "First number for the calculation"
                },
                "second_number": {
                    "type": "number",
                    "description": "Second number for the calculation"
                }
            },
            "required": ["operator", "first_number", "second_number"],
        }
    }
}

Inspect the complete calculator tool definition, including its object type, properties, enum constraint, and required inputs. section 3.2.1

How Build an AI Agent (From Scratch) covers it

How deep it goes
Explains object types, properties, enums, and required fields, but stops short of broader schema validation internals.
Examples
Uses a calculator definition, arithmetic enum, multiplication request, parsed arguments, and returned result.
What you can do after
Build it from scratch by defining calculator parameters and processing the model's generated tool arguments.
How it connects
Connects JSON Schema with tool calling, function definitions, argument parsing, and function execution.

Also explained in

Compare how 4 books explain JSON Schema →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build an AI Agent (From Scratch). The section links point to the parts of the book it draws on.