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%.
@@ -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,
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"
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
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).
- 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
- GitHub issue: #9411
- Fix PR: https://github.com/pydantic/pydantic/pull/9508
- First fixed release: 2.7.2
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.58
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, Indeed, looks like our type hints could be improved. Would you be interested in opening a PR to fix this issue? Thanks for bringing…”
“Can we keep ValidationInfo's type annotations for context instead of Model.model_validate[_json] please? I.e”
Failure Signature (Search String)
- Type of validation context
- This context is made available to validators via the ValidationInfo object.
Copy-friendly signature
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 Message
-------------
Type of validation context
This context is made available to validators via the ValidationInfo object.
Minimal Reproduction
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
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.
When NOT to Use This Fix
- Do not use this fix if your code relies on the previous dict type for context.
Verify Fix
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
| Version | Status |
|---|---|
| 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.