Jump to solution
Verify

The Fix

pip install pydantic==2.7.2

Based on closed pydantic/pydantic issue #9411 · 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
@@ -327,7 +327,7 @@ def model_dump( include: IncEx = None, exclude: IncEx = None, - context: dict[str, Any] | None = None, + context: Any | None = None, by_alias: bool = False,
repro.py
from typing import Any from pydantic import BaseModel, model_validator from pydantic_core.core_schema import ValidationInfo class Model(BaseModel): @model_validator(mode="after") def validator(self, info: ValidationInfo) -> Any: info.context # this returns a object of type "Any | None" Model.model_validate_json("{}", context={}) # type of context has to be "dict[str, Any] | None"
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.7.2\nWhen NOT to use: Do not use this fix if your code relies on the previous dict type for context.\n\n

Why This Fix Works in Production

  • Trigger: Type of validation context
  • Mechanism: The type hint for the validation context was incorrectly set to dict[str, Any] instead of Any
  • Why the fix works: Fixed the type hint of the validation context to be Any | None instead of dict[str, Any] | None. (first fixed release: 2.7.2).
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

  • The type hint for the validation context was incorrectly set to dict[str, Any] instead of Any
  • Production symptom (often without a traceback): Type of validation context

Proof / Evidence

Discussion

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

“@sydney-runkle I have fixed the type hints in 9508 I agree with @mjog that Any is the correct type.”
@OhioDschungel6 · 2024-05-27 · source
“@OhioDschungel6, Indeed, looks like our type hints could be improved. Would you be interested in opening a PR to fix this issue? Thanks for bringing…”
@sydney-runkle · 2024-05-16 · source
“Can we keep ValidationInfo's type annotations for context instead of Model.model_validate[_json] please? I.e”
@mjog · 2024-05-26 · source

Failure Signature (Search String)

  • Type of validation context
  • This context is made available to validators via the ValidationInfo object.
Copy-friendly signature
signature.txt
Failure Signature ----------------- Type of validation context This context is made available to validators via the ValidationInfo object.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Type of validation context This context is made available to validators via the ValidationInfo object.

Minimal Reproduction

repro.py
from typing import Any from pydantic import BaseModel, model_validator from pydantic_core.core_schema import ValidationInfo class Model(BaseModel): @model_validator(mode="after") def validator(self, info: ValidationInfo) -> Any: info.context # this returns a object of type "Any | None" Model.model_validate_json("{}", context={}) # type of context has to be "dict[str, Any] | None"

Environment

  • Pydantic: 2

What Broke

Type errors occurred when passing non-dict objects to validation functions.

Why It Broke

The type hint for the validation context was incorrectly set to dict[str, Any] instead of Any

Fix Options (Details)

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

pip install pydantic==2.7.2

When NOT to use: Do not use this fix if your code relies on the previous dict type for context.

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/9508

First fixed release: 2.7.2

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

  • Do not use this fix if your code relies on the previous dict type for context.

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.7.2 Fixed

Related Issues

No related fixes found.

Sources

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