tiangolo/fastapi · error · PydanticV1NotSupportedError
pydantic.v1 models are no longer supported by FastAPI. Pleas
Error message
pydantic.v1 models are no longer supported by FastAPI. Please update the response model {type_!r}. What it means
`create_model_field` (utils.py:66-70) raises `PydanticV1NotSupportedError` (a `FastAPIError` subclass, exceptions.py:246) when `annotation_is_pydantic_v1(type_)` is true for a field annotation. This version of FastAPI only supports pydantic v2, so any `pydantic.v1.BaseModel` subclass used as a response_model, request body, query dependency, or embedded field type triggers it at app/route construction.
Source
Thrown at fastapi/utils.py:67
"check that {type_} is a valid Pydantic field type. "
"If you are using a return type annotation that is not a valid Pydantic "
"field (e.g. Union[Response, dict, None]) you can disable generating the "
"response model from the type annotation with the path operation decorator "
"parameter response_model=None. Read more: "
"https://fastapi.tiangolo.com/tutorial/response-model/"
)
def create_model_field(
name: str,
type_: Any,
default: Any | None = Undefined,
field_info: FieldInfo | None = None,
alias: str | None = None,
mode: Literal["validation", "serialization"] = "validation",
) -> ModelField:
if annotation_is_pydantic_v1(type_):
raise PydanticV1NotSupportedError(
"pydantic.v1 models are no longer supported by FastAPI."
f" Please update the response model {type_!r}."
)
field_info = field_info or FieldInfo(annotation=type_, default=default, alias=alias)
try:
return v2.ModelField(mode=mode, name=name, field_info=field_info)
except PydanticSchemaGenerationError:
raise fastapi.exceptions.FastAPIError(
_invalid_args_message.format(type_=type_)
) from None
def generate_operation_id_for_path(
*, name: str, path: str, method: str
) -> str: # pragma: nocover
warnings.warn(
message="fastapi.utils.generate_operation_id_for_path() was deprecated, "
"it is not used internally, and will be removed soon",View on GitHub (pinned to 42a41db11f)
Solutions
- Migrate the model to pydantic v2: `from pydantic import BaseModel` and update validators/`Config` to v2 idioms.
- If you cannot migrate, disable response model generation for that endpoint with `response_model=None`.
- Replace the v1 model annotation with a plain `dict` or a v2 model, or return a `Response` directly.
- Upgrade or replace the third-party package that still exposes `pydantic.v1` models.
Example fix
# before
from pydantic.v1 import BaseModel
class Item(BaseModel):
name: str
@app.get("/items/{i}", response_model=Item)
def read_item(i: int): ...
# after
from pydantic import BaseModel
class Item(BaseModel):
name: str
@app.get("/items/{i}", response_model=Item)
def read_item(i: int): ... Defensive patterns
Strategy: validation
Validate before calling
import pydantic
def assert_pydantic_v2_model(model: type) -> None:
"""Reject pydantic.v1 models used as FastAPI field/response types."""
if hasattr(pydantic, "v1") and issubclass(model, pydantic.v1.BaseModel):
raise TypeError(
f"{model!r} is a pydantic.v1 model, no longer supported. Migrate to pydantic v2."
)
# usage, e.g. in a startup scan of declared response models
for m in (Item, Order, User):
assert_pydantic_v2_model(m) Type guard
import pydantic
def is_pydantic_v2_model(obj: object) -> bool:
return (
isinstance(obj, type)
and issubclass(obj, pydantic.BaseModel)
and not (hasattr(pydantic, "v1") and issubclass(obj, pydantic.v1.BaseModel))
) Try / catch
# Construction-time failure: catch at bootstrap so the service logs a clear cause.
from fastapi.exceptions import PydanticV1NotSupportedError
try:
app.include_router(legacy_router) # router exposes a v1 response_model
except PydanticV1NotSupportedError as exc:
raise SystemExit(
f"Startup aborted: {exc}. Migrate the model to pydantic v2 or set response_model=None."
) from exc Prevention
- After upgrading pydantic, grep the codebase for `pydantic.v1` and `from pydantic.v1` and migrate every hit.
- Import `BaseModel` only from the top-level `pydantic` package.
- For endpoints you cannot migrate immediately, set `response_model=None` or return a plain `dict`/`Response`.
- Audit third-party SDKs that expose model types before annotating endpoints with them.
When it happens
Trigger: Using `from pydantic.v1 import BaseModel` and annotating a path operation or `response_model=` with it; a third-party library that still ships v1 models and exposes them as types; embedding a v1 model inside a v2 model field; importing `BaseModel` from the wrong (compat) location after an upgrade.
Common situations: Upgrading FastAPI/pydantic without migrating models; mixing `pydantic.v1` compat shims left over from a 1.x->2.x migration; a dependency (SDK, ORM plugin) returning v1 models that you annotate as `response_model`.
Related errors
- pydantic.v1 models are no longer supported by FastAPI. Pleas
- {"errors": exc.errors(), "body": body.decode()}
- {"errors": exc.errors(), "body": body.decode()}
- e.errors(include_url=False)
- Invalid ID format, it must start with "isbn-" or "imdb-"
AI-assisted analysis of tiangolo/fastapi@42a41db11f (2026-08-04).
Data as JSON: /data/errors/f1c2c44a6cfbe32f.json.
Report an issue: GitHub.