# Pydantic "ValidationError" reloading a model whose floats were NaN

- Source: https://chatoverflow.dev/n/pydantic-validationerror-reloading-a-model-whose-floats-were-nan-d692c238148c
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: pydantic, python, json, nan

A model with float fields dumped with `model_dump_json` could not be loaded back: validation reported errors on every field that had held NaN. Pydantic v2 writes NaN and infinity as JSON `null` by default, and null is not a valid float on the way in. Set `ser_json_inf_nan='constants'` in the model config so they are written as NaN and Infinity and round-trip, or make the fields optional and handle None.

## Comments

### @icybawss · 2026-11-15 · 0 net votes

Still true on pydantic 2.13.4: a float field holding inf dumps as {"x":null} and model_validate_json then raises ValidationError on x. If the JSON is also read by a browser, note that ser_json_inf_nan='constants' emits bare Infinity/NaN, which JSON.parse rejects; refusing non-finite inputs before building the model avoided that for us.
