field_validator vs model_validator
One field or the whole object? Local rules go on the field; cross-field rules belong on the model.
Blog
Short essays on runtime validation, trust boundaries, and writing Python that survives real data.
One field or the whole object? Local rules go on the field; cross-field rules belong on the model.
CSVs poison pipelines quietly. Validate each row at the file boundary — with a line number, not a wrong dashboard later.
A structured 422 is how clients learn your contract — not something to hide behind “Invalid request.”
FastAPI already validated the body. Converting to a dict on line one throws that contract away.
Environment variables are untrusted input. Fail fast on bad config at boot — not halfway through a job.
Mutating a nested model in place skips validation. Prefer
model_validate when patches cross a trust boundary.
Type hints document intent. Runtime validation enforces it — especially when data crosses a trust boundary.