The Fix
pip install pydantic==2.11.8
Based on closed pydantic/pydantic issue #12096 · 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%.
@@ -3020,6 +3020,11 @@ class Model(BaseModel, validate_assignment=True):
+# The following 3 tests define a `__get_pydantic_core_schema__()` method on Pydantic models.
+# This isn't explicitly supported and can lead to unexpected side effects, but are here
+# to prevent potential regressions:
from typing import Annotated
from pydantic import BaseModel, GetCoreSchemaHandler
from pydantic_core import CoreSchema
class Metadata(BaseModel):
foo: str = "metadata!"
bar: int = 100
@classmethod
def __get_pydantic_core_schema__(cls, source_type: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema:
if cls is not source_type:
return handler(source_type)
return super().__get_pydantic_core_schema__(source_type, handler)
class Model(BaseModel):
state: Annotated[int, Metadata()]
m = Model.model_validate({"state": 2})
print(repr(m))
#> Model(state=2)
print(m.model_fields)
#> {'state': FieldInfo(annotation=int, required=True, metadata=[Metadata(foo='metadata!', bar=100)])}
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.11.8\nWhen NOT to use: Do not use this fix if you rely on custom metadata handling in Pydantic models.\n\nOption C — Workaround\nunnecessary. It turns out the promised simplification DOES NOT WORK.\nWhen NOT to use: Do not use this fix if you rely on custom metadata handling in Pydantic models.\n\n
Why This Fix Works in Production
- Trigger: [7833](https://github.com/pydantic/pydantic/issues/7833) brought up an issue about pydantic expecting metadata in `typing.Annotated` to be provided when…
- Mechanism: Adds tests to prevent regression with Pydantic models used as annotated metadata, addressing the issue where metadata in `Annotated` is not accepted as promised.
- Why the fix works: Adds tests to prevent regression with Pydantic models used as annotated metadata, addressing the issue where metadata in `Annotated` is not accepted as promised. (first fixed release: 2.11.8).
- 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
- Production symptom (often without a traceback): [7833](https://github.com/pydantic/pydantic/issues/7833) brought up an issue about pydantic expecting metadata in `typing.Annotated` to be provided when instantiating a model. We agreed that's incorrect behaviour.
Proof / Evidence
- GitHub issue: #12096
- Fix PR: https://github.com/pydantic/pydantic/pull/12133
- First fixed release: 2.11.8
- 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.46
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Although we are still in unknown territory, this should work: Can you confirm it works on your end? I'm hesitant to go with changes like…”
“With regards to my PR, I infer you are trusting your test suite not enough to allow any pydantic model instance as metadata in typing.Annotated”
“Thanks for the in-depth conversation”
“> With regards to my PR, I infer you are trusting your test suite not enough to allow any pydantic model instance as metadata in…”
Failure Signature (Search String)
- [7833](https://github.com/pydantic/pydantic/issues/7833) brought up an issue about pydantic expecting metadata in `typing.Annotated` to be provided when instantiating a model. We
- A [workaround](https://github.com/pydantic/pydantic/issues/7833#issuecomment-1765244660) by @sydney-runkle works fine. However, the dunder method used there
Copy-friendly signature
Failure Signature
-----------------
[7833](https://github.com/pydantic/pydantic/issues/7833) brought up an issue about pydantic expecting metadata in `typing.Annotated` to be provided when instantiating a model. We agreed that's incorrect behaviour.
A [workaround](https://github.com/pydantic/pydantic/issues/7833#issuecomment-1765244660) by @sydney-runkle works fine. However, the dunder method used there (`__get_pydantic_core_schema__ `) is deprecated.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
[7833](https://github.com/pydantic/pydantic/issues/7833) brought up an issue about pydantic expecting metadata in `typing.Annotated` to be provided when instantiating a model. We agreed that's incorrect behaviour.
A [workaround](https://github.com/pydantic/pydantic/issues/7833#issuecomment-1765244660) by @sydney-runkle works fine. However, the dunder method used there (`__get_pydantic_core_schema__ `) is deprecated.
Minimal Reproduction
from typing import Annotated
from pydantic import BaseModel, GetCoreSchemaHandler
from pydantic_core import CoreSchema
class Metadata(BaseModel):
foo: str = "metadata!"
bar: int = 100
@classmethod
def __get_pydantic_core_schema__(cls, source_type: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema:
if cls is not source_type:
return handler(source_type)
return super().__get_pydantic_core_schema__(source_type, handler)
class Model(BaseModel):
state: Annotated[int, Metadata()]
m = Model.model_validate({"state": 2})
print(repr(m))
#> Model(state=2)
print(m.model_fields)
#> {'state': FieldInfo(annotation=int, required=True, metadata=[Metadata(foo='metadata!', bar=100)])}
Environment
- Pydantic: 2
What Broke
Models fail to accept metadata as intended, leading to incorrect behavior.
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.11.8
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Option C — Workaround Temporary workaround
unnecessary. It turns out the promised simplification DOES NOT WORK.
Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.
Fix reference: https://github.com/pydantic/pydantic/pull/12133
First fixed release: 2.11.8
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if you rely on custom metadata handling in Pydantic models.
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.11.8 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.