pydantic
pydantic is a library that describes the shape of your data with classes and type hints, and validates it when you create the object.
Used in 28 lessons of the course, from 01.04.
pydantic is a package that does not ship with Python: you install it separately (pip install pydantic). You import it with from pydantic import BaseModel, Field, field_validator, as in lesson 01.04.
The idea: you write a class that inherits from BaseModel and declare its fields with type hints. When you create an object, pydantic checks the data. If a value can be converted to the requested type (for example "3" to 3), it converts it. If not, it raises a ValidationError with a clear message.
BaseModel: the base class for your models.Field: adds rules or descriptions to a field.field_validator: your own function that validates one specific field.
Why it matters in the course: data coming from a language model comes with no guarantees. A pydantic model makes sure that, if the object exists, it has the right shape.
Reach for it when: you need data to have a guaranteed shape and types, especially if it comes from outside your code.
