FastAPI 0.162.0 changes how omitted boolean form fields are handled. Previously, the framework implicitly inferred False for any boolean form field that a client did not submit. With this release, omitted bool and bool | None form fields either fall back to their declared defaults or raise a missing-field error, matching the behavior of every other field type and of Pydantic itself. The change is tagged as a breaking change in the release notes and comes from PR #16605 by @tiangolo.
The release notes list the following concrete effects:
- Individual form parameters, form models, and unions of form models all follow the new rule: no implicit
Falseinjection for omitted booleans. - Omitted boolean model fields are excluded from
model_dump(exclude_unset=True)rather than appearing with a synthesized value. - Default values on boolean fields no longer count as submitted fields during union selection, so a union branch is not chosen just because a boolean has a default.
- Default factories and
validate_defaultbehave according to the usual rules, so callables producing defaults run as expected. - For HTML checkboxes, the recommended pattern is to declare a boolean field with an explicit default of
False, since unchecked boxes send nothing at all. Details are in the Boolean Form Fields documentation section.
For developers, this removes a long-standing inconsistency that could mask missing input: a client that forgot to send a flag previously looked identical to one that explicitly sent false. Endpoints that relied on the implicit inference should now declare = False explicitly, otherwise requests omitting the field will return validation errors. The upside is predictable semantics across scalars, models, and unions, plus cleaner output from model_dump(exclude_unset=True) when building partial updates. Applications mixing boolean form fields with optional unions should be tested after upgrading.
Source: https://github.com/fastapi/fastapi/releases/tag/0.162.0