If a FastAPI error appears in your interface as [object Object], first inspect the raw response: FastAPI allows the response’s detail value to be either a string or structured JSON. The display usually needs to select a field from that object or format it, rather than show the object as though it were already a message. That frontend explanation is a diagnostic inference; FastAPI’s documentation establishes the response shape, not how a particular client renders it.
What FastAPI puts in an error response
FastAPI’s documented HTTP exception response places the error value in a top-level detail field. A simple string detail looks like this:
As an Amazon Associate I earn from qualifying purchases.
{"detail": "Item not found"}
But detail is not limited to strings. The FastAPI error-handling guide says you can pass any value convertible to JSON, including a dictionary or list. For example, a structured detail could look like this:
Free tools Windows power users keep installed
One-click scans. No signup required.
{"detail": {"message": "Item not found", "code": "missing_item"}}
The example’s message and code fields are illustrative; FastAPI permits JSON-convertible values but does not require this particular structure.
#1 Best Overall
Why a structured detail can appear as [object Object]
If the raw response contains a JSON object under detail, but the page shows [object Object], the likely issue is in the client-side display path: the interface is treating an object as if it were a ready-to-show string. This is an inference from the response shape, not behavior verified by the FastAPI documentation. Check the frontend expression that renders the error. If the object has a human-readable field, display that field; if you want to expose the whole structure for debugging, format it as JSON instead.
Trace the error before changing the backend
- Inspect the raw response body. Use the browser’s network tools or the API client making the request. Confirm whether
detailis a string, object, or list. - Compare the raw value with the visible message. If the response contains a useful string but the interface shows
[object Object], focus on the client’s rendering code. Ifdetailis structured, identify which field should be shown to users. - Choose a display rule. Render a suitable text field for a normal error message, or format the complete structure when the intended audience needs diagnostic detail. Do not assume every
detailvalue is a string. - Change the FastAPI response only if its shape is unsuitable. A structured detail may be useful when clients need machine-readable information; a string may be more appropriate when the response is meant to be a single human-readable message.
How FastAPI’s default handler builds the response
FastAPI’s default handler wraps the exception’s detail as {"detail": exc.detail} and returns it with the exception’s status code and headers when a response body is allowed. The response wrapper therefore does not mean that the nested value is necessarily a string. The handler implementation is visible in the FastAPI exception-handler source; because master is a mutable branch, it should not be treated as a pinned release reference.
Rank #2
Custom handlers and the Starlette exception class
FastAPI’s HTTPException inherits from Starlette’s HTTPException. FastAPI allows any JSON-able value for detail, while Starlette’s class accepts only strings. The FastAPI documentation recommends registering a custom handler for Starlette’s HTTPException when you want to handle exceptions raised by Starlette internals or extensions as well as FastAPI’s own exceptions.
Recommended Free Tools
That distinction matters when a custom handler appears not to catch every framework error: check which exception class the handler is registered for, and whether it covers Starlette’s base class. It is separate from the display problem—choosing the right handler does not automatically make an object-valued detail a user-facing string.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




