Checking your account

You can read the lesson while its saved answers and constructions load. Learning controls will open once that work is ready.

Pydantic Constraints and Validators

Field and Model Validation in Pydantic v2

BOTIE

A handwritten record check can begin with a few conditions, then grow as records acquire nested fields and relationships. The same rules are easy to scatter across constructors and handlers. A schema-based validator keeps that declared contract together while reporting where an input failed.

Pydantic’s 2022 v2 design described a tree of validators and separate ways to apply custom checks. The resulting v2 interfaces distinguish checks on one field from checks on a completed model. This is a useful engineering distinction even without the library: a rule about one count needs that count, while a rule comparing two endpoints needs both endpoints.

Sources for this history