Jump to solution
Verify

The Fix

pip install pydantic==2.6.0

Based on closed pydantic/pydantic issue #8529 · PR/commit linked

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -394,6 +394,8 @@ with the help of the [`@model_validator`](validators.md#model-validators) decora from typing import Any, Dict +from typing_extensions import Self + from pydantic import model_validator
repro.py
from typing import Any from pydantic import BaseModel, ValidationError, model_validator class UserModel(BaseModel): username: str password1: str password2: str @model_validator(mode='before') @classmethod def check_card_number_omitted(cls, data: Any) -> Any: if isinstance(data, dict): assert ( 'card_number' not in data ), 'card_number should not be included' return data @model_validator(mode='after') def check_passwords_match(self) -> 'UserModel': pw1 = self.password1 pw2 = self.password2 if pw1 is not None and pw2 is not None and pw1 != pw2: raise ValueError('passwords do not match') return self
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install pydantic==2.6.0\nWhen NOT to use: This fix is not applicable if the return type of model validators is correctly defined.\n\n

Why This Fix Works in Production

  • Trigger: Type errors with @model_validator
  • Mechanism: Type errors occur due to incorrect return type annotations in model validators
  • Why the fix works: Updates the documentation to fix type annotations related to the @model_validator, addressing the type errors reported in issue #8529. (first fixed release: 2.6.0).
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • Shows up under Python 3.11 in real deployments (not just unit tests).
  • Type errors occur due to incorrect return type annotations in model validators
  • Production symptom (often without a traceback): Type errors with @model_validator

Proof / Evidence

Verified Execution

We executed the runnable minimal repro in a temporary environment and captured exit codes + logs.

  • Status: PASS
  • Ran: 2026-02-11T16:52:29Z
  • Package: pydantic
  • Fixed: 2.6.0
  • Mode: fixed_only
  • Outcome: ok
Logs
affected (exit=None)
fixed (exit=0)

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“> At any rate, you should be able to eliminate this type error in your own code by setting the return type as typing_extensions.Self instead…”
@noctuid · 2024-01-25 · source
“@not-my-profile, Thanks for bringing this to our attention. We're looking into this issue and a potential fix 👍.”
@sydney-runkle · 2024-01-10 · source
“Sidenote: The type error for mode='before' appears to be different and apparently was addressed yesterday with #8479.”
@not-my-profile · 2024-01-10 · source
“@noctuid and @not-my-profile, I just updated the docs with fixes for these type annotations. Thanks for bringing this to our attention :).”
@sydney-runkle · 2024-01-25 · source

Failure Signature (Search String)

  • Type errors with @model_validator
  • The fix for #7152 was merged in v2.2.2 but apparently there has been a regression because with pydantic 2.5.3 pyright again reports a type error. It should be noted that this
Copy-friendly signature
signature.txt
Failure Signature ----------------- Type errors with @model_validator The fix for #7152 was merged in v2.2.2 but apparently there has been a regression because with pydantic 2.5.3 pyright again reports a type error. It should be noted that this doesn't only happen for `mode="wrap"`.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Type errors with @model_validator The fix for #7152 was merged in v2.2.2 but apparently there has been a regression because with pydantic 2.5.3 pyright again reports a type error. It should be noted that this doesn't only happen for `mode="wrap"`.

Minimal Reproduction

repro.py
from typing import Any from pydantic import BaseModel, ValidationError, model_validator class UserModel(BaseModel): username: str password1: str password2: str @model_validator(mode='before') @classmethod def check_card_number_omitted(cls, data: Any) -> Any: if isinstance(data, dict): assert ( 'card_number' not in data ), 'card_number should not be included' return data @model_validator(mode='after') def check_passwords_match(self) -> 'UserModel': pw1 = self.password1 pw2 = self.password2 if pw1 is not None and pw2 is not None and pw1 != pw2: raise ValueError('passwords do not match') return self

Environment

  • Python: 3.11
  • Pydantic: 2.5.3

Why It Broke

Type errors occur due to incorrect return type annotations in model validators

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install pydantic==2.6.0

When NOT to use: This fix is not applicable if the return type of model validators is correctly defined.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/pydantic/pydantic/pull/8639

First fixed release: 2.6.0

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not applicable if the return type of model validators is correctly defined.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
  • Upgrade behind a canary and run integration tests against the canary before 100% rollout.

Version Compatibility Table

VersionStatus
2.6.0 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.