Distinguishing between "set to default" and "accepted default" in Pydantic?
13:28 21 Dec 2025

Is there a way of distinguishing between "accepted the default" and "missing" in Pydantic?

Example:

from pydantic import BaseModel

class Test(BaseModel):
    c: str | None = None

k1 = Test.model_validate({'c': None})

k2 = Test.model_validate({})

I'd like to be able to distinguish between case k1, where c was explicitly set to the default, compared to k2 where field was not supplied at all.

pydantic