Model Inputs with Pydantic
Define a typed shape for a tool's arguments.
A Model Per Input
To shape a tool's arguments, you write a Pydantic model: a small class where each attribute is one typed field of the input.
from pydantic import BaseModel
class SearchInput(BaseModel):
query: str
limit: intSubclass BaseModel
Every input model inherits from BaseModel, which gives it parsing, validation, and JSON schema generation for free.
All lessons in this course
- Why Schemas Beat Loose Args
- Model Inputs with Pydantic
- Constraints, Defaults & Enums
- Field Descriptions That Guide the Model