tiangolo/fastapi · error · PydanticV1NotSupportedError
pydantic.v1 models are no longer supported by FastAPI…
Error message
pydantic.v1 models are no longer supported by FastAPI. Please update the response model {type_!r}. What it means
Raised by `create_model_field` (fastapi/utils.py:67) as `PydanticV1NotSupportedError` when `annotation_is_pydantic_v1(type_)` returns True for a response model (or field) type. FastAPI no longer supports `pydantic.v1` models as response models / field types; only Pydantic v2 models are accepted. The offending type is shown via `{type_!r}` so you can locate it.
Solutions
- Migrate the model to Pydantic v2: `from pydantic import BaseModel` and update field syntax.
- If you cannot migrate yet, wrap/convert the v1 model to a v2 model (or a plain type) before using it as a response model.
- Disable response model generation for that endpoint with `response_model=None` if conversion is not feasible.
Example fix
// before
from pydantic.v1 import BaseModel
class Item(BaseModel):
name: str
@app.get('/items', response_model=list[Item])
// after
from pydantic import BaseModel
class Item(BaseModel):
name: str
@app.get('/items', response_model=list[Item]) Defensive patterns
Strategy: type-guard
Validate before calling
import pydantic
def is_pydantic_v2(model) -> bool:
bases = getattr(model, '__mro__', ())
return any(b.__module__.startswith('pydantic') and b.__name__ == 'BaseModel'
and not b.__module__.startswith('pydantic.v1') for b in bases)
# before using a model as response_model:
assert is_pydantic_v2(MyModel), 'migrate to pydantic v2' Type guard
def is_v2_model(type_: object) -> bool:
import pydantic
return isinstance(type_, type) and issubclass(type_, pydantic.BaseModel) Prevention
- Search the codebase for 'pydantic.v1' imports and migrate them.
- Pin compatible fastapi/pydantic versions and run the full test suite on upgrade.
- If a third-party returns v1 models, convert to v2 at the boundary before returning.
When it happens
Trigger: Declaring a path operation whose return type or `response_model` references a model imported from `pydantic.v1` (e.g. `from pydantic.v1 import BaseModel`). Using a third-party library that still ships pydantic v1 models as response types. Mixing `pydantic` and `pydantic.v1` BaseModels in the same app.
Common situations: Upgrading FastAPI to a version that dropped v1 support while still importing v1 models. Inheriting from `pydantic.v1.BaseModel` for backwards compatibility. A dependency returns a v1 model annotated as the response type.
Related errors
- validation error(s)
- pydantic.v1 models are no longer supported by FastAPI…
- {errors}
- {"errors": exc.errors(), "body": body.decode()}
- {"errors": exc.errors(), "body": body.decode()}
AI-assisted analysis of tiangolo/fastapi@3e8d1526d8 (2026-08-11).
Data as JSON: /api/errors/f1c2c44a6cfbe32f.
Report an issue: GitHub.
Appendix: 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 3e8d1526d8)