Skip to main content

One post tagged with "basemodel"

basemodel tag description

View All Tags

Deep dive into pydantic BaseModel class decorators

· 9 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Pydantic BaseModel class decorators are a powerful and modern way to customize a model's behavior and validation logic. While a lot of Pydantic's functionality is configured through class attributes or the ConfigDict, decorators offer a more explicit and code-centric approach, especially for complex validation.

Pydantic V2 introduced several new decorators to enhance validation and model configuration. The most important ones are:

  • @model_validator
  • @field_validator
  • @computed_field

These decorators are typically imported from pydantic.