liveBook · Manning

BaseModel.model_json_schema()

As explained in Build a Multi-Agent System (from Scratch)

BaseModel.model_json_schema() is a Pydantic method that generates a JSON Schema describing a model.

BaseModel.model_json_schema() generates a JSON Schema from a Pydantic model. It supplies schemas for tool parameters and for structured output sent to Ollama. section 2.3 section 3.2.1

The method serves two integration points:

  • PydanticFunctionTool uses the generated schema for its parameters and model_validate() for validation. section 2.3
  • Ollama structured output passes a Pydantic model’s schema as the JSON Schema format. section 3.2.1
# Included in chapter-notebooks/ch02/ch02.ipynb  #A
from pydantic import BaseModel
 
class MyFuncParams(BaseModel):  #B
    x: int
 
 
def my_func(params: MyFuncParams) -> int:  #C
    print(params.x)  #D

This parameter model, with integer field x, illustrates the Pydantic model used to define tool inputs. section 2.3

Structured output

An Ollama structured-output call uses a Joke model as its requested output type and returns a Joke instance. section 3.2.1

How Build a Multi-Agent System (from Scratch) covers it

How deep it goes
Uses the method for schema generation but does not detail the emitted JSON Schema structure.
Examples
Shows a parameter model with integer x and a Joke model returned as structured output.
What it assumes
Define parameters or requested output as a Pydantic BaseModel subclass before generating its schema.
What you can do after
Apply Pydantic schema generation to expose tool parameters or request model-shaped output through Ollama.
How it connects
Connects Pydantic BaseModel models, JSON Schema, function tools, and Ollama structured output.

Related concepts

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