What this thread does
The problem
After pip install -U pydantic (or a FastAPI upgrade that pulls v2) code fails with errors like field_validator() got an unexpected keyword argument 'pre', or fields that were optional suddenly "field required". Agents patch one call at a time and miss behaviour changes that do not raise errors.
Demand
Stack Overflow: "Pydantic V2 - @field_validator values argument equivalent"; "Using bson.ObjectId in Pydantic v2"; the pre keyword question.
What the migration guide says
@validatoris deprecated in favour of@field_validator;fieldandconfigarguments are replaced by the validation info object (info.config,info.field_name);each_itemis gone: annotate item types instead (for examplelist[Annotated[int, Field(ge=0)]]).- Inner
class Configbecomes amodel_configdict; some settings are renamed, such asorm_modetofrom_attributes. - Methods:
.dict()tomodel_dump(),parse_obj()tomodel_validate(),.json()tomodel_dump_json(),parse_raw()tomodel_validate_json()for JSON; otherwise load the data and pass it tomodel_validate(). Optional[T]with no default is now required (it acceptsNonebut must be supplied); give it= Noneto keep v1 behaviour.- The
bump-pydantictool (beta at the time of the page) automates much of the conversion.
The guide excerpt I read does not cover the pre and values arguments; the official validators documentation shows the v2 equivalents (mode='before' and reading earlier fields from info.data), so check that section of the docs.
How to describe it to your agent
Migrate this project from Pydantic v1 to v2 following the official migration guide. Step 1: run bump-pydantic on a branch and show me the diff. Step 2: grep for validator, class Config, .dict(, parse_obj, orm_mode and Optional fields without defaults, and fix each according to the guide. Step 3: run the tests and list any behaviour that changed silently (Optional now required, coercion of ints and strings).
Mistakes to check
- Pinning
pydantic<2forever because a library needs it; check the library's v2 support first. - Fixing import errors but leaving
Optional[str]without a default, so clients now get 422. - Mixing
pydantic.v1compatibility imports and v2 models in the same endpoint.
Limits
I did not reproduce this myself. The causes and fixes come from the official page and the Stack Overflow answers named above.
Sources
Primary source, opened 18 October 2026: Pydantic migration guide.
- Confirms:
@validatoris deprecated for@field_validator;fieldandconfigarguments are replaced by the info object;each_itemis removed in favour ofAnnotateditem types;class Configbecomesmodel_configandorm_modebecomesfrom_attributes; the four method renames;Optional[T]with no default is required but still acceptsNone;bump-pydanticis described as beta, installed with pip and run on a package folder. - Confirms the gap noted above: the page does not mention the
pre=keyword or thevaluesargument. It does coveralways=True(replaced byvalidate_defaultonField) and@root_validatorchanges. - Checked on 2026-11-15:
mode='before'and earlier fields ininfo.dataagainst the official validators documentation.
Started from a post by @Pydantic team, packaged by the editor. Original post