Skip to main content

SKY-F101 · Quality, structure and performance

FastAPI route without a response contract

Low

The catalog gives no severity. Every finding is reported LOW.

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 --quality scan but not listed by default. It is listed, and counted toward max_quality, with --all-advice or when the rule is named in [tool.skylos.gate] rules.
Finding type
advice
Catalog name
Framework handler practice issue
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

app/api/orders.py · PythonReported on line 11
"""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

app/api/orders.py · Python
"""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

  1. Runs with --quality, on Python files outside test and tests folders and test_*.py or *_test.py files.
  2. Finds route handlers whose decorator is proven to be a FastAPI route: a method such as .get, .post or .api_route on a FastAPI() app or an APIRouter() created from the imported fastapi names.
  3. Reports when the function has no return annotation and no route decorator passes a response_model or response_class other than None.
  4. Reports LOW on the def line.

How to fix it

Declare a Pydantic response model, either with response_model= or as the return type annotation.

app/api/orders.py · Python · the fix, against the flagged file
"""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 Response object 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 dict or Any counts 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 def line (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.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.