{"record":{"id":"f1c2c44a6cfbe32f","repo":"tiangolo/fastapi","slug":"pydantic-v1-models-are-no-longer-supported-by-fast-f1c2c4","errorCode":null,"errorMessage":"pydantic.v1 models are no longer supported by FastAPI. Please update the response model {type_!r}.","messagePattern":"pydantic\\.v1 models are no longer supported by FastAPI\\. Please update the response model (.+?)\\.","errorType":"exception","errorClass":"PydanticV1NotSupportedError","httpStatus":null,"severity":"error","filePath":"fastapi/utils.py","lineNumber":67,"sourceCode":"    \"check that {type_} is a valid Pydantic field type. \"\n    \"If you are using a return type annotation that is not a valid Pydantic \"\n    \"field (e.g. Union[Response, dict, None]) you can disable generating the \"\n    \"response model from the type annotation with the path operation decorator \"\n    \"parameter response_model=None. Read more: \"\n    \"https://fastapi.tiangolo.com/tutorial/response-model/\"\n)\n\n\ndef create_model_field(\n    name: str,\n    type_: Any,\n    default: Any | None = Undefined,\n    field_info: FieldInfo | None = None,\n    alias: str | None = None,\n    mode: Literal[\"validation\", \"serialization\"] = \"validation\",\n) -> ModelField:\n    if annotation_is_pydantic_v1(type_):\n        raise PydanticV1NotSupportedError(\n            \"pydantic.v1 models are no longer supported by FastAPI.\"\n            f\" Please update the response model {type_!r}.\"\n        )\n    field_info = field_info or FieldInfo(annotation=type_, default=default, alias=alias)\n    try:\n        return v2.ModelField(mode=mode, name=name, field_info=field_info)\n    except PydanticSchemaGenerationError:\n        raise fastapi.exceptions.FastAPIError(\n            _invalid_args_message.format(type_=type_)\n        ) from None\n\n\ndef generate_operation_id_for_path(\n    *, name: str, path: str, method: str\n) -> str:  # pragma: nocover\n    warnings.warn(\n        message=\"fastapi.utils.generate_operation_id_for_path() was deprecated, \"\n        \"it is not used internally, and will be removed soon\",","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/tiangolo/fastapi/blob/3e8d1526d83a90aaf7d6eb6dc682bf150f180b25/fastapi/utils.py#L49-L85","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nfrom pydantic.v1 import BaseModel\nclass Item(BaseModel):\n    name: str\n\n@app.get('/items', response_model=list[Item])\n// after\nfrom pydantic import BaseModel\nclass Item(BaseModel):\n    name: str\n\n@app.get('/items', response_model=list[Item])","handlingStrategy":"type-guard","validationCode":"import pydantic\n\ndef is_pydantic_v2(model) -> bool:\n    bases = getattr(model, '__mro__', ())\n    return any(b.__module__.startswith('pydantic') and b.__name__ == 'BaseModel'\n               and not b.__module__.startswith('pydantic.v1') for b in bases)\n\n# before using a model as response_model:\nassert is_pydantic_v2(MyModel), 'migrate to pydantic v2'","typeGuard":"def is_v2_model(type_: object) -> bool:\n    import pydantic\n    return isinstance(type_, type) and issubclass(type_, pydantic.BaseModel)","tryCatchPattern":null,"preventionTips":["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."],"tags":["fastapi","pydantic","response-model","migration","version-change"],"backgroundTag":null,"analyzedSha":"3e8d1526d83a90aaf7d6eb6dc682bf150f180b25","analyzedAt":"2026-08-11T02:34:52.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}