The Fix
pip install pydantic==2.11.8
Based on closed pydantic/pydantic issue #12024 · 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%.
@@ -288,7 +288,7 @@ By leveraging the new [`type` statement](https://typing.readthedocs.io/en/latest
=== "Python 3.9 and above"
- ```python
+ ```python {test="skip"}
from typing import Annotated
from pydantic import BaseModel
type A = Annotated[int, Field(default=5)]
class M1(BaseModel):
a1: A
print(M1.model_json_schema().get("required")) # None which is fine to me
class M2(BaseModel):
a1: A
a2: A
print(M2.model_json_schema().get("required")) # ['a1', 'a2'] which is weird, I'd expect no required
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 apply this fix if the behavior of required fields is intentionally designed.\n\n
Why This Fix Works in Production
- Trigger: JSON Schema inconsistently sets Annotated type aliases as required or not
- Mechanism: The JSON Schema generation inconsistently marks fields as required based on type alias definitions
- Why the fix works: Emit a warning when field-specific metadata is used in invalid contexts, addressing JSON Schema inconsistencies. (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
- The JSON Schema generation inconsistently marks fields as required based on type alias definitions
- Production symptom (often without a traceback): JSON Schema inconsistently sets Annotated type aliases as required or not
Proof / Evidence
- GitHub issue: #12024
- Fix PR: https://github.com/pydantic/pydantic/pull/12028
- Fix commit: https://github.com/pydantic/pydantic/commit/3a7fe26ad40a49c1e7130224c2fb00188180fe63
- 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.62
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“This is actually expected, as per the warning in the documentation”
“Warning implemented in https://github.com/pydantic/pydantic/pull/12028.”
“A warning sounds great, without it it was fairly confusing, thank you!”
Failure Signature (Search String)
- JSON Schema inconsistently sets Annotated type aliases as required or not
- print(M1.model_json_schema().get("required")) # None which is fine to me
Copy-friendly signature
Failure Signature
-----------------
JSON Schema inconsistently sets Annotated type aliases as required or not
print(M1.model_json_schema().get("required")) # None which is fine to me
Error Message
Signature-only (no traceback captured)
Error Message
-------------
JSON Schema inconsistently sets Annotated type aliases as required or not
print(M1.model_json_schema().get("required")) # None which is fine to me
Minimal Reproduction
from pydantic import BaseModel
type A = Annotated[int, Field(default=5)]
class M1(BaseModel):
a1: A
print(M1.model_json_schema().get("required")) # None which is fine to me
class M2(BaseModel):
a1: A
a2: A
print(M2.model_json_schema().get("required")) # ['a1', 'a2'] which is weird, I'd expect no required
Environment
- Pydantic: 2
What Broke
Users experience unexpected required fields in JSON Schema, leading to validation errors.
Why It Broke
The JSON Schema generation inconsistently marks fields as required based on type alias definitions
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.
Fix reference: https://github.com/pydantic/pydantic/pull/12028
First fixed release: 2.11.8
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not apply this fix if the behavior of required fields is intentionally designed.
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.