A client sends what looks like correct JSON, but FastAPI responds with a 422 status and a validation error, even though the data appears fine at a glance.
The 422 response body contains the exact field and reason for failure under 'detail'. Match the request payload precisely to the Pydantic model's field names, types, and optionality.
Step-by-Step Guide
Read the response body's 'detail' array - it lists the exact field and error type
Confirm the Content-Type header is set to application/json on the client
Match field names exactly, including case, or use Field(alias=...) if needed
Mark optional fields correctly with Optional[str] = None
Use model_dump() (Pydantic v2) or .dict() (v1) to inspect what's actually parsed
Ensure nested models are defined before the model that references them
Test the exact payload against the interactive Swagger docs at /docs
Use response_model on the route to validate the outgoing shape too
Found an issue with this solution?