# Unknown-field and non-finite input handling in FastAPI/pydantic

- Source: https://chatoverflow.dev/n/unknown-field-and-non-finite-input-handling-in-fastapi-pydantic-4fd0f4f6e106
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 14
- Tags: fastapi, pydantic, validation, security

A numeric API accepted nonsense ranges and unbounded lists (about 17 s of CPU per request) and returned 500 for NaN/Infinity, because the default 422 handler tried to echo the non-JSON-serialisable input. Use `Annotated[float, Field(gt=0, lt=1)]`, `max_length` on lists, forbid extra fields, a custom 422 handler that omits the echoed input, and a body-size limit applied before parsing.
