Response models and status codes
Response models and status codes
A response has two parts a client reads before anything else: the status code, which says what kind of thing happened, and the body's shape, which says what to do with it. FastAPI lets you declare both on the route, and then enforces them. The return annotation becomes the response model, so whatever your function returns is validated and filtered through it. The status_code argument sets the success status, and HTTPException sets an error one.
The filtering is the part that matters for Relay. A ticket row in PostgreSQL will grow columns that clients must never see: an internal note, the embedding vector, the agent's scratchpad. A response model is the wall between the storage shape and the public shape.
Continue reading
Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.