Skip to content

Adopt 422 Unprocessable Entity for payload validation errors #568

@nanotaboada

Description

@nanotaboada

Context

FastAPI already returns 422 Unprocessable Entity by default for Pydantic validation failures, which is the correct and semantically precise behavior. This ticket exists to make that choice explicit and intentional rather than an implicit framework default.

Proposed Solution

  • Document the intentional use of 422 vs 400 in route docstrings (validation failure → 422, malformed request → 400)
  • Verify all manually raised HTTPException instances use the correct code for their category
  • Ensure OpenAPI docs explicitly declare 422 responses on the relevant endpoints

Acceptance Criteria

  • Route docstrings document 422 for validation failures and 400 for malformed requests
  • All manual HTTPException instances verified against the 400 vs 422 distinction
  • OpenAPI route decorators declare responses={422: {"description": "Unprocessable Entity"}} where applicable
  • All existing tests continue to pass
  • CHANGELOG.md updated

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority lowNice-to-have improvement. Can be deferred without blocking other work.pythonPull requests that update Python code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions