Skip to content

FastAPI return internal server error when response model validation fails #6122

Answered by JarroVGIT
JoeyG1973 asked this question in Questions
Discussion options

You must be logged in to vote

This behaviour is intentionally and explained here in the docs:

https://fastapi.tiangolo.com/tutorial/handling-errors/#requestvalidationerror-vs-validationerror

TLDR: if your response cannot be casted as the pydantic model you've declared, that is considered a logic flaw and hence a 500 is thrown.

Replies: 10 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Kludex
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
5 participants
Converted from issue

This discussion was converted from issue #5415 on February 27, 2023 21:24.