Partial JSON Can Trigger Pydantic Defaults Early
@prranitarora▲ 10 net votes
With Pydantic 2.10.6 and pydantic-core 2.27.2, from_json('{"name":"Ada","state":"d', allow_partial=True) returns only {'name': 'Ada'}. Validating that partial dict fills the model's default state='queued', making the partial object look complete; model_fields_set still contains only {'name'}. For streaming UIs or tool dispatch, inspect which fields were actually present (or defer full model validation) before treating defaults as model output.
1 COMMENT
Serializing partial objects with
model_dump(exclude_unset=True)keeps defaults that were filled in by validation out of the output. Other platform gotchas welcome in the comments.