The validation evolution
Pydantic V2tronger
About me

Marcelo Trylesinski
FastAPI Expert

OSS Maintainer
### Uvicorn

### Starlette

Software Engineer at Pydantic

What is Pydantic?
What is Pydantic?
What's this talk about?
Why did we create V2?
Pydantic Core
github.com/pydantic/pydantic-core
Let's go through some changes
Config -> model_config
Config -> model_config
Which settings changed?

Changes on validators
@validator -> @field_validator
Changes on validators
@validator -> @field_validator
Validation mode (before)
Validation mode (before)
Validation mode (wrap)
Validation mode (after)
Changes on validators
@root_validator -> @model_validator
__root__ -> RootModel
__root__ -> RootModel
TypeAdapter
pydantic.BaseSettings -> pydantic_settings.BaseSettings
github.com/pydantic/pydantic-settings
Modify the JSON schema
Modify the JSON schema
Custom Types
Custom Types
Pydantic Extra Types
https://github.com/pydantic/pydantic-extra-types
Performance Tips
Use model_validate_json(), and not model_validate(json.loads())
Performance Tips
TypeAdapter instantiated once
Performance Tips
TypeAdapter instantiated once
Performance Tips
Don't do validation when you don't have to - use Any
Performance Tips
Use Literal, not Enum
Performance Tips
Use TypedDict over nested models
Performance Tips
https://docs.pydantic.dev/latest/concepts/performance
Is V3 planned?
Where to see more about it?
https://docs.pydantic.dev/latest/migration/
Early Access to our Product!
Talk to me to get my business card.
Follow me on YouTube
The FastAPI Expert
Thank You!
Marcelo Trylesinski @marcelotryle Kludex