SKY-F101 · Quality, structure and performance
FastAPI route without a response contract
FastAPI uses a route's response_model, response_class or return type annotation to validate, filter and document what the route sends back. SKY-F101 reports a FastAPI route that has none of the three. The catalog calls the rule "Framework handler practice issue".
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans). Advice that is measured on every
--qualityscan but not listed by default. It is listed, and counted towardmax_quality, with--all-adviceor when the rule is named in[tool.skylos.gate] rules. - Finding type
- advice
- Catalog name
- Framework handler practice issue
Why it matters
Without a response model, the route returns whatever the function returns: a database row with a password hash or an internal note goes straight to the client, and the OpenAPI schema says nothing about the shape clients should expect.
What Skylos flags
"""Order API.""" from fastapi import FastAPI from app.db import load_order app = FastAPI() @app.get("/orders/{order_id}")def get_order(order_id: int): return load_order(order_id)What Skylos leaves alone
"""Order API.""" from fastapi import FastAPIfrom pydantic import BaseModel from app.db import load_order app = FastAPI() class OrderOut(BaseModel): id: int total: float @app.get("/orders/{order_id}", response_model=OrderOut)def get_order(order_id: int): return load_order(order_id)Why Skylos leaves it alone
The route declares response_model=OrderOut, so FastAPI keeps only the id and total fields of whatever load_order returns.
How Skylos decides
- Runs with
--quality, on Python files outsidetestandtestsfolders andtest_*.pyor*_test.pyfiles. - Finds route handlers whose decorator is proven to be a FastAPI route: a method such as
.get,.postor.api_routeon aFastAPI()app or anAPIRouter()created from the importedfastapinames. - Reports when the function has no return annotation and no route decorator passes a
response_modelorresponse_classother thanNone. - Reports LOW on the
defline.
How to fix it
Declare a Pydantic response model, either with response_model= or as the return type annotation.
"""Order API.""" from fastapi import FastAPIAdded: from pydantic import BaseModel from app.db import load_order app = FastAPI() Added: class OrderOut(BaseModel):Added: id: intAdded: total: floatAdded: Added: @app.get("/orders/{order_id}")Removed: def get_order(order_id: int):Removed: return load_order(order_id)Added: def get_order(order_id: int) -> OrderOut:Added: return OrderOut.model_validate(load_order(order_id))When it can be wrong
- A route that returns a
Responseobject it builds itself, such as a file download, is reported when it has no annotation, although a response model would not apply. - A return annotation of
dictorAnycounts as a contract, even though it filters nothing.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
On the
defline (the reported line):Python def get_order(order_id: int): # skylos: ignore[SKY-F101] streams a PDF[tool.skylos] ignore = ["SKY-F101"]turns the rule off for the project. A baseline accepts existing findings, but it records the absolute file path and the line, so an entry stops matching when the checkout moves or the line shifts.