---
source: https://iinventedlight.com/library/notes/fastapi-response-model.md
title: "Response models and return types in FastAPI"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE); prose restates or closely paraphrases cited source lines"
license_family: fastapi-mit
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "Summary by iinventedlight (AI-assisted). Sources: FastAPI docs, Response Model - Return Type - FastAPI, MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE); FastAPI docs, Extra Models - FastAPI, MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: FastAPI"
tags: ['fastapi', 'pydantic', 'response-model']
sources:
  - id: S1
    title: "Response Model - Return Type - FastAPI"
    publisher: FastAPI docs
    url: https://fastapi.tiangolo.com/tutorial/response-model/
    accessed: 2026-11-04
    license: "MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE)"
  - id: S2
    title: "Extra Models - FastAPI"
    publisher: FastAPI docs
    url: https://fastapi.tiangolo.com/tutorial/extra-models/
    accessed: 2026-11-04
    license: "MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE)"
---
# Response models and return types in FastAPI

**Answer:** You can declare the type used for the response by annotating the path operation function return type. You can use Pydantic models, lists, dictionaries, scalar values like integers, booleans, etc. (S1)

## What it buys you

- If the data is invalid (e.g. you are missing a field), it means that your app code is broken, and it will return a server error instead of returning incorrect data. (S1)
- This way you and your clients can be certain that they will receive the data and the data shape expected. (S1)
- FastAPI will add a JSON Schema for the response, in the OpenAPI path operation. (S1)
- It will also be used by automatic client code generation tools. (S1)

## Separate models

- It will be common to have more than one related model. (S2)
- The input model needs to be able to have a password, and the database model would probably need to have a hashed password. (S2)

## Claims
- id: C1
  claim: Annotate the return type to declare the response.
  source: S1
  evidence: "you can use the path operation decorator parameter response_model instead of the return type."
- id: C2
  claim: Invalid output returns a server error.
  source: S1
  evidence: "and it will return a server error instead of returning incorrect data."
- id: C3
  claim: A JSON Schema is added to OpenAPI.
  source: S1
  evidence: "Add a JSON Schema for the response, in the OpenAPI path operation."
- id: C4
  claim: Related models are common.
  source: S2
  evidence: "it will be common to have more than one related model."

## Sources
- [S1] Response Model - Return Type - FastAPI. FastAPI docs. https://fastapi.tiangolo.com/tutorial/response-model/ . License: MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE). Accessed 2026-11-04.
- [S2] Extra Models - FastAPI. FastAPI docs. https://fastapi.tiangolo.com/tutorial/extra-models/ . License: MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
