Type hints generate the data contract, the /docs page, and the OpenAPI file at the same time, so the client's application team can try it before you leave.

Key takeaways

  • FastAPI is built on type hints, Pydantic, and the OpenAPI/JSON Schema standards, so schemas and the /docs page require no extra work.
  • response_model filters out undeclared fields and would rather return a server error than return wrong data, so the contract is genuinely enforced.
  • The project has not reached 1.0 yet (version 0.157.0 was released on 2026-10-21), so pin the version for every demo you hand to a client.

It's Tuesday afternoon and you're on-site with a client. Their data scientist hands you a notebook containing a model that predicts delivery delays and asks: "Can the application team call this?" The best answer by end of day is a link the client can try themselves, with a clear schema and tests.

FastAPI was made for exactly this moment. The official documentation defines it as a Python web framework for building APIs based on standard Python type hints. It is open source under the MIT license, and the official repository is at github.com/fastapi/fastapi.

For a Forward Deployed Engineer (FDE), its value is that one piece of code produces three things at once: a data contract, interactive documentation, and an API that can be tested immediately. Before a client can trust that your demo can go to production, they need to see all three.

Why does documentation appear as soon as the code is written?

FastAPI is built on two open standards: OpenAPI (formerly Swagger) and JSON Schema. You declare data types with type hints and Pydantic models, and the framework converts them into schemas. There is no separate "write documentation" step, so nothing can be forgotten.

Concretely: once the app starts, with no additional configuration, /docs provides an interactive documentation page powered by Swagger UI. Next to it, /openapi.json is the complete API description. The client's application team can use this file to generate SDKs or verify the contract without reading your code.

The tool's origins also fit the work of wrapping models. FastAPI's author, Sebastián Ramírez (@tiangolo), also created Typer and SQLModel. He says he spent years building APIs with complex requirements, involving machine learning, distributed systems, and asynchronous tasks. FastAPI is built on top of Pydantic and Starlette.

A model-wrapping endpoint, line by line

Take the delivery-delay model from above. The client's internal data table also stores recipients' phone numbers, a field that must never flow to external applications. The minimal endpoint looks like this, where

score_late

is a hypothetical function that calls the client's model:

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class ShipmentIn(BaseModel):
    shipment_id: str
    distance_km: float
    warehouse_id: str

class Prediction(BaseModel):
    shipment_id: str
    late_probability: float

@app.post("/predict", response_model=Prediction)
def predict(shipment: ShipmentIn):
    row = load_shipment(shipment.shipment_id)  # 包含 customer_phone
    return {
        "shipment_id": shipment.shipment_id,
        "late_probability": score_late(shipment),
        "customer_phone": row["customer_phone"],
    }

The dict returned by the function has three fields, while

Prediction

declares only two. According to the documentation, FastAPI uses Pydantic to filter out all data outside the output model, so

customer_phone

never leaves the server. When wrapping real client data, this is exactly the mechanism you need: a momentary oversight in the handler doesn't become a data leak.

Conversely, FastAPI is just as strict. If the handler returns something that doesn't match

Prediction

—for example, missing

late_probability

—FastAPI returns a server error rather than emitting wrong data. The response model also attaches the output's JSON Schema to the OpenAPI description, so the /docs page describes exactly what the application team will receive.

Write tests in the same session, without starting a server

A demo is only credible with tests, and FastAPI keeps the cost low here. Just install httpx and use pytest.

TestClient

Built on HTTPX, tests run in-process—no server to start, no ports to open.

from fastapi.testclient import TestClient
from app import app

client = TestClient(app)

def test_phone_never_leaks():
    r = client.post("/predict", json={
        "shipment_id": "S-001",
        "distance_km": 12.5,
        "warehouse_id": "HCM-1",
    })
    assert r.status_code == 200
    assert "customer_phone" not in r.json()

Even if the endpoint is asynchronous, the test function is just a plain

def

, not

async def

. This lets you write tests within a working session, even sitting right next to the client's engineers. This should be the first test you write: it turns the promise of "no personal data leaks" into an assert line everyone can understand.

Two common mistakes when wrapping real data

The first is omitting the output model. All the filtering above depends on it; without this model, FastAPI has no field list to compare against. The consequence is obvious: whatever the handler returns is what the client may receive,

customer_phone

included.

The second is returning ORM objects directly, or entire rows from the client's table. Today that table has only five harmless columns; next month the data team adds a column of personal information, and without a filtering layer, the new column goes out with the rest of the data—and nobody notices.

The safe habit is to always go through a dedicated output model, even if it nearly duplicates the table structure. Also keep a test like

test_phone_never_leaks

in your test suite, so if someone accidentally removes

response_model

, the test fails before the client sees any data leak.

Limitations to explain to the client

FastAPI has not reached 1.0. The official release notes list version 0.157.0 from 2026-10-21, showing the project is still actively releasing but remains in the 0.x stage. The practical advice: pin the exact version in the dependency file of every demo you deliver, so when the client reinstalls months later, the results are exactly the same.

The second limitation is scope. FastAPI handles the contract layer and HTTP communication; it won't make the client's model faster or more accurate. If the model takes several seconds per prediction, the endpoint will be just as slow no matter how polished, and operational issues in the client's environment remain yours to solve.

What to learn first, and what to put on your resume

A sensible order is to learn type hints and Pydantic models first, since everything else is generated from them. Next comes

response_model

, then

TestClient

. These three are enough to take you from a notebook to a documented, tested API in one afternoon.

If an FDE job description mentions building prototypes or integrating with client systems, this skill is worth discussing. Don't just list "FastAPI" in the skills section of your resume.

A sentence like "Wrapped the client's prediction model as an API with an OpenAPI schema and automated tests preventing personal data leaks, delivered in one day" explains both the technology and how you work with clients.

The next time someone asks "Can the application team call this?", your answer should be a /docs link and a passing test.

Was this article helpful?

Thanks for your feedback!

Next on the roadmap · Phase 2: Full-stack engineering skills: Use Zod to block bad data from client APIs before an agent acts. MCP's TypeScript SDK already depends on Zod; one schema at the entry point handles both runtime validation and type generation, so the two never drift apart.