Answers for LLM inference engineers

ImportError: cannot import name 'BaseSettings' (or ModelMetaclass, field_validator, any name) from 'pydantic...': which pydantic releases have it

pydantic 2.0 (2023-06-30) moved BaseSettings to the separate pydantic-settings package and removed 197 names, which now raise PydanticImportError; 1.10.27 is the last 1.x. Fix the first with pip install pydantic-settings and from pydantic_settings import BaseSettings. For the others, either move to the 2.x API (table below) or import the old name from pydantic.v1, which carries the whole 1.x API in every 2.x release (and, as an alias, in 1.10.15 and later). validator and root_validator still import in 2.14.4, with a deprecation warning. For any other name, paste the error below.

Published 2026-11-25 · Data as of 2026-11-25 · the first release of every minor, pydantic 0.0.2 to 2.14.4 (59 releases), with patch releases that differ noted · read from the release tags, nothing was installed or run (how, limits) · Corrected 2026-12-05

Corrected on 2026-12-05: this page read only the first release of each minor version, so a name added or removed in a patch release was dated to the next minor. For example, the lookup said the module pydantic.v1 exists from 2.0; it is also in 1.10.15 (2024-04-03) and every later 1.10.x. And from pydantic import AnyWebsocketUrl works from 2.7.1 (2024-04-23), not only from 2.8.0. Every release was then read once from PyPI: 35 top-level names (and 1,542 module-and-name pairs in all) differ in some patch release from the first release of the same minor. The lookup now gives those patch releases. The per-minor ranges are unchanged.

Examples:

Runs in your browser on pydantic.json (217 KB) and 165 KB of hints in this page; nothing you paste is sent anywhere. Covers 6,432 module-and-name pairs in 114 modules.

What replaces the 1.x names in 2.x?

1.x2.x
BaseSettingspip install pydantic-settings; from pydantic_settings import BaseSettings
validator, root_validator (still import, deprecated)field_validator, model_validator
class Config: inside a modelmodel_config = ConfigDict(...)
parse_obj_as, schema_of (still import, deprecated)TypeAdapter(T).validate_python(...), .json_schema()
pydantic.main.ModelMetaclassprivate: pydantic._internal._model_construction.ModelMetaclass
pydantic.fields.ModelFieldpydantic.fields.FieldInfo, Model.model_fields
Required, ConstrainedStr, constr-style classes, stricturl, parse_raw_as and 190 moreraise PydanticImportError; pydantic.v1 keeps them
PyObjectImportString (redirected with a warning from 2.1.0)
pydantic.generics.GenericModelBaseModel with Generic[T] (redirected with a warning from 2.1.0)

Moved names are listed in pydantic/_migration.py: 30 of them still import from the old place in 2.14.4 and warn (for example pydantic.utils.deep_update, served from pydantic.v1.utils); the 197 removed ones raise. The lookup counts the first group as importable and gives the message for the second.

How was this read, and how was it checked?

From the Python files at the release tags of pydantic/pydantic (the first release of every minor, plus the latest), parsed with Python's ast module. The tags match the wheels on PyPI (every .py file compared by git blob hash at 1.10.0, 2.0, 2.7.0 and 2.14.4). A module's names are everything it binds at module level, what from .x import * brings in, the names of the lazy-import table that pydantic/__init__.py serves through __getattr__ from 2.0, and the moved names of the migration table in each module that installs getattr_migration.

Checks: (1) the top-level names are found as plain text in pydantic/__init__.py (or its migration table) in every release of their range (7,988 name-and-release pairs) and are not bound on either side (443 edges). (2) A regular expression finds 19,496 definitions in 1,219 file versions; all are among the names read. (3) 19 release checks by text search in the tagged files agree:

NameReleaseText and data
pydantic.BaseSettings1.10.0importable
pydantic.BaseSettings2.0not importable
pydantic.main.ModelMetaclass1.10.0importable
pydantic.main.ModelMetaclass2.0not importable
pydantic.field_validator1.10.0not importable
pydantic.field_validator2.0importable
pydantic.ConfigDict1.9.0not importable
pydantic.ConfigDict1.10.0importable
pydantic.TypeAdapter2.0importable
pydantic.utils.deep_update2.0importable
pydantic.Required1.10.0importable
pydantic.Required2.0not importable
pydantic.with_config2.6.0not importable
pydantic.with_config2.7.0importable
pydantic.generics.GenericModel2.0not importable
pydantic.generics.GenericModel2.1.0importable
pydantic.v1.BaseModel2.0importable
pydantic.v11.10.14not importable (text only)
pydantic.v11.10.15importable (text only)

Limits

Questions

How do I fix "cannot import name 'BaseSettings' from 'pydantic'"?

pydantic 2.0 (2023-06-30) moved it to its own package: pip install pydantic-settings, then from pydantic_settings import BaseSettings. In 2.x the error is PydanticImportError: "`BaseSettings` has been moved to the `pydantic-settings` package." To keep old code unchanged, pin pip install "pydantic<2" (1.10.27 is the last 1.x).

What does "PydanticImportError: `pydantic:Required` has been removed in V2" mean?

197 names (in 2.14.4) are listed in pydantic's migration table as removed; importing one raises this error. Each has a 2.x replacement (Required becomes a field without a default, ConstrainedStr becomes Annotated[str, StringConstraints(...)], parse_raw_as becomes TypeAdapter(T).validate_json). To keep the 1.x behaviour, import it from pydantic.v1, which carries the whole 1.x API from 2.0 on.

How do I fix "cannot import name 'ModelMetaclass' from 'pydantic.main'"?

pydantic 2.0 moved the metaclass to the private module pydantic._internal._model_construction. Code that needs it on 2.x imports it from there (it can change without notice); code written for 1.x can use from pydantic.v1.main import ModelMetaclass.

How do I fix "cannot import name 'field_validator' from 'pydantic'"?

You have pydantic 1.x: field_validator, model_validator, TypeAdapter and computed_field are new in 2.0. pip install "pydantic>=2", or keep validator and root_validator, which work in both.

Can one codebase import from pydantic.v1 on both 1.x and 2.x?

Yes, from pydantic 1.10.15: that release added a pydantic.v1 module that aliases the 1.x namespace, so from pydantic.v1 import BaseModel works on 1.10.15 and later and on every 2.x.

Sources

The same data as JSON: pydantic.json, licensed CC BY 4.0.

Related: "cannot import name ... from 'langchain'" · "... from 'openai'" · "... from 'llama_index'".