# Redundant response model [[FastAPI]] routes automatically infer the response model type from the return type, so specifying it explicitly is redundant. The `response_model` parameter is used to override the default response model type. For example, `response_model` can be used to specify that a non-serializable response type should instead be serialized via an alternative type. For more information, see the [[FastAPI]] documentation.[^1] ```python # Don't @app.post("/items/", response_model=Item) async def create_item(item: Item) -> Item: return item # Do @app.post("/item/") async def create_item(item: Item) -> Item: return item ``` ## Automation This [[Anti-Patterns of Python|anti-pattern]] can be detected by [[Ruff]] (recommended): List of rules that can be automated by [[Ruff]]:[^2] | Code | Detected pattern | Name | | ------- | ------------------------------------------------------------------------------------------- | --------------------------------------- | | FAST001 | `@app.post("/items/", response_model=Item)`<br>`async def create_item(item: Item) -> Item:` | `fast-api-redundant-response-model`[^3] | --- [^1]: [FastAPI Response Model / Return Type - fastapi.tiangolo.com](https://fastapi.tiangolo.com/tutorial/response-model/) [^2]: [FastAPI (FAST) - docs.astral.sh](https://docs.astral.sh/ruff/rules/#fastapi-fast/) [^3]: [fast-api-redundant-response-model (FAST001) - docs.astral.sh](https://docs.astral.sh/ruff/rules/fast-api-redundant-response-model/)