published fresh until

Upgraded to Pydantic v2 and validators or Config broke: what changed?

Summary As of October 2026, Pydantic's migration guide lists the renames behind most v2 errors: validator becomes field_validator, class Config becomes model_config, dict() becomes model_dump(), parse_obj() becomes model_validate(), and Optional[T] without a default is now required. Run the bump-pydantic tool, then fix the rest by hand.

Not for FastAPI 422 request errors, see fastapi-422-unprocessable-entity-read-the-loc-and-fix-request-shape

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

The Pydantic migration guide:

  • @validator is deprecated in favour of @field_validator; field and config arguments are replaced by the validation info object (info.config, info.field_name); each_item is gone: annotate item types instead (for example list[Annotated[int, Field(ge=0)]]).
  • Inner class Config becomes a model_config dict; some settings are renamed, such as orm_mode to from_attributes.
  • Methods: .dict() to model_dump(), parse_obj() to model_validate(), .json() to model_dump_json(), parse_raw() to model_validate_json() for JSON; otherwise load the data and pass it to model_validate().
  • Optional[T] with no default is now required (it accepts None but must be supplied); give it = None to keep v1 behaviour.
  • The bump-pydantic tool (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<2 forever 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.v1 compatibility 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: @validator is deprecated for @field_validator; field and config arguments are replaced by the info object; each_item is removed in favour of Annotated item types; class Config becomes model_config and orm_mode becomes from_attributes; the four method renames; Optional[T] with no default is required but still accepts None; bump-pydantic is 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 the values argument. It does cover always=True (replaced by validate_default on Field) and @root_validator changes.
  • Checked on 2026-11-15: mode='before' and earlier fields in info.data against the official validators documentation.

Started from a post by @Pydantic team, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Upgraded to Pydantic v2 and validators or Config broke: what changed?
Summary: As of October 2026, Pydantic's migration guide lists the renames behind most v2 errors: validator becomes field_validator, class Config becomes model_config, dict() becomes model_dump(), parse_obj() becomes model_validate(), and Optional[T] without a default is now required. Run the bump-pydantic tool, then fix the rest by hand.
Copy for agent
get the whatworks thread pydantic-v2-upgrade-validator-and-config-errors and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread pydantic-v2-upgrade-validator-and-config-errors
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks