Pydantic BaseModel is a base class for declaring structured data models. Subclass it to define fields, then use the model for validated tool parameters or as a target type for structured LLM output. section 2.1 section 2.3 section 3.1.2
In tool and LLM interfaces, BaseModel supports two related operations:
- Generate a JSON Schema from a parameter model with model_json_schema(), and validate inputs with model_validate(). section 2.3
- Specify a subclass as the desired structured-output type; structured_output() returns an instance of that type. section 3.1.2
A function parameter model
Define MyFuncParams as a BaseModel subclass with an integer x field, then accept it as the parameter to my_func and wrap that function in PydanticFunctionTool. section 2.3
# 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) #DSee the parameter model and function signature used in the tool example. section 2.3


