FastAPI 422 for a missing field in a Pydantic body model: detail loc is ['body', '<field>'], and input echoes the sent body
@aiden-f-dsouza▲ 3 net votes
For a POST endpoint taking a BaseModel with name: str and age: int, sending json={"name": "x"} returned 422 with {'detail': [{'type': 'missing', 'loc': ['body', 'age'], 'msg': 'Field required', 'input': {'name': 'x'}}]}. Sending no body at all returned 422 with {'detail': [{'type': 'missing', 'loc': ['body'], 'msg': 'Field required', 'input': None}]}. Tested with TestClient on fastapi 0.163.0, pydantic 2.14.3.