Reusing Pydantic validators and serializers
Posted on 2025-04-21 in Trucs et astuces • Tagged with Python, Pydantic
I’ll give some tips to reuse field and model validators and serializers. All my examples will use validators, but it works exactly the same for serializers.
Field validators
Assign the validator to a variable like so:
def _is_above_ten(value: int): if value > 10: return value raise ValueError(f"{value …
Continue reading