Error message
FastAPI 422 Unprocessable Entity
FastAPI answers 422 when the request doesn’t match what the route declared: a missing field, a wrong type, a body that isn’t JSON. It is not an exception on your server: the framework handles it and replies. So the Sentry SDK doesn’t report it by default, and Errilo shows nothing, which is usually what you want.
Examples run on 21 November 2026 with Python 3.13.18, FastAPI 0.165.0 and sentry-sdk 2.11.0, 2.40.0 and 2.75.0. Errilo is in private beta.
What the response says
A route that expects a JSON body:
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
price: float
@app.post("/items")
def create_item(item: Item):
return itemPosting {"name": "x", "price": "abc"} returns 422 Unprocessable Entity with this body:
{"detail": [{"type": "float_parsing", "loc": ["body", "price"],
"msg": "Input should be a valid number, unable to parse string as a number",
"input": "abc"}]}Each entry of detail says where (loc: body, path, query…), why (type and msg) and what was received (input). That is the whole diagnosis: read it from the response, or from the client’s network tab.
The usual causes
Observed with the route above and a path parameter declared as int:
| Request | type, loc |
|---|---|
Field missing: {"name": "x"} | missing, ["body", "price"] |
Wrong type: "price": "abc" | float_parsing, ["body", "price"] |
Path parameter: GET /items/abc | int_parsing, ["path", "item_id"] |
Right JSON, but Content-Type: text/plain | model_attributes_type, ["body"] |
A form (name=x&price=1) sent to a JSON route | model_attributes_type, ["body"] |
When the body is “valid dictionary” in the message, look at the request first: the client sent a form or the wrong Content-Type, not wrong values.
What the Sentry SDK captures
We sent the failing request through an app with sentry_sdk.init() and nothing else, and counted the events that reached the server. The same with 2.11.0, 2.40.0 and 2.75.0:
| What the route does | Response | Events |
|---|---|---|
Invalid body (a RequestValidationError) | 422 | 0 |
raise HTTPException(status_code=422) | 422 | 0 |
raise HTTPException(status_code=404) | 404 | 0 |
raise RuntimeError("boom") | 500 | 1 (RuntimeError, mechanism starlette) |
The Starlette and FastAPI integrations only report an HTTPException whose status is in failed_request_status_codes. The default is the 5xx range: range(500, 599) in 2.11.0, a set of 500 to 599 in 2.40.0 and 2.75.0. A 422 is outside it. A validation error isn’t even an HTTPException: FastAPI turns it into a response before the SDK sees an exception.
Reporting 422s anyway
Adding 422 to failed_request_status_codes on both integrations reports the HTTPException(422) you raise yourself, and still nothing for a validation error: we got 1 event for the first and 0 for the second, with the three versions.
import sentry_sdk
from sentry_sdk.integrations.fastapi import FastApiIntegration
from sentry_sdk.integrations.starlette import StarletteIntegration
sentry_sdk.init(
dsn="https://<key>@ingest.errilo.com/<project>",
integrations=[
StarletteIntegration(failed_request_status_codes={422}),
FastApiIntegration(failed_request_status_codes={422}),
],
)To report validation errors, call the SDK from an exception handler for RequestValidationError:
import sentry_sdk
from fastapi import Request
from fastapi.exception_handlers import request_validation_exception_handler
from fastapi.exceptions import RequestValidationError
@app.exception_handler(RequestValidationError)
async def on_validation_error(request: Request, exc: RequestValidationError):
sentry_sdk.capture_exception(exc) # reports the 422, then answers as usual
return await request_validation_exception_handler(request, exc)In our test, that sent one event per failing request: RequestValidationError, mechanism generic, with the request (method and URL). Two things to know before you do it:
- The message contains what the client sent. The
inputof each error is part of the exception text: a rejected value like a password field or an e-mail address goes to Errilo with it. - Every 422 is one issue. The stack trace has only FastAPI and Starlette frames, so Errilo’s fingerprint is the same for all routes: two failures on different routes and models gave the same fingerprint. You can’t tell routes or fields apart in the issue list.
RequestValidationError: 1 validation error:
{'type': 'int_parsing', 'loc': ('body', 'age'), 'msg': 'Input should be a valid integer, unable to parse string as an integer', 'input': 'secret-value'}A 422 is the client’s mistake, so we’d keep it out of the error tracker: count the 422s per route in your logs or metrics, and keep Errilo for the 5xx. If a client reports a 422, the response body already says which field.
What Errilo shows
With the default settings, nothing: a 422 never leaves your server as an event, so there is no issue. A 5xx raised in a route arrives as usual (see the FastAPI guide). If you do report 422s as above, they all land in a single RequestValidationError issue, titled with the text of the first error, and without a culprit since none of the frames is yours.
Errilo has no inbound filters on the server: what you don’t want to see has to be dropped in the SDK. The simplest filter for 422s is not to report them.