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) #DThis 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
