python runtime_error ai_generated true

fastapi.exceptions.RequestValidationError: field required

ID: python/fastapi-requestvalidationerror-field-required

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
0.100.x active
0.110.x active

Root Cause

A required field is missing from the request body, query parameters, or path parameters according to the Pydantic model.

generic

中文

根据 Pydantic 模型,请求体、查询参数或路径参数中缺少必填字段。

Workarounds

  1. 95% success
    class Item(BaseModel):
        name: str = "default"
  2. 90% success
    Check the OpenAPI docs at /docs to verify the expected schema and send all required fields.

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Optional without a default still requires the field to be present (can be None). The error persists.

  2. 85% fail

    This affects response validation, not request validation.