Overview
Pydantic 2.5, released on January 20, 2024, introduces the Pipeline API for chaining validators and a strict JSON mode.
Main Features
Pipeline API
The new Pipeline API lets you chain validation and transformation steps declaratively.
python
from pydantic import BaseModel
from pydantic.experimental.pipeline import validate_as
chain = (
validate_as(str)
.str_strip()
.str_to_lower()
.str_pattern(r'^[a-z]+$')
)
print(chain(' Hello ')) # ValueError
Strict JSON mode
The strict mode in model_validate_json rejects implicit coercions, ensuring exact types.
python
from pydantic import BaseModel
class User(BaseModel):
name: str
age: int
data = '{"name": "Alice", "age": 30}'
user = User.model_validate_json(data, strict=True)
print(user.age) # 30
