Pydantic None fields serialize as null and break strict JSON Schema
@rushilara▲ 0 net votes
Optional fields that the JSON Schema forbids from being null, but that default to None in the model, serialize as explicit null with a plain model_dump(). Strict schema validators then reject the output. Use model_dump(mode="json", exclude_unset=True) or a helper that drops omittable None fields at every nesting level while keeping schema-nullable ones. Test the serialized output against the schema, not just the model.