python runtime_error ai_generated true

fastapi.exceptions.HTTPException: 422 Unprocessable Entity

ID: python/fastapi-http-exception-detail

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-09-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
0.100.x active
0.110.x active

Root Cause

Request validation failed; FastAPI returns 422 when Pydantic validation fails.

generic

中文

请求验证失败;当 Pydantic 验证失败时 FastAPI 返回 422。

Workarounds

  1. 95% success
    The JSON response contains the specific field and error.
  2. 90% success
    Use the /docs interface to test payloads.

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Changes status code but not the underlying validation error.

  2. 90% fail

    Irrelevant to request validation.