The Fix
pip install pydantic==2.10.4
Based on closed pydantic/pydantic issue #9269 · 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%.
@@ -85,11 +85,27 @@ def is_literal(tp: Any, /) -> bool:
-# TODO remove and replace with `get_args` when we drop support for Python 3.8
-# (see https://docs.python.org/3/whatsnew/3.9.html#id4).
def literal_values(tp: Any, /) -> list[Any]:
from typing import Literal
from pydantic import BaseModel
type TestType0 = Literal["test1", "test2"]
type TestType1 = Literal[TestType0, Literal["test3"]]
type TestType2 = Literal[Literal["test1", "test2"], Literal["test3"]]
# TestType1 does not work
# TestType2 works
class Model(BaseModel):
f: TestType1
print(Model.model_json_schema())
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.10.4\nWhen NOT to use: This fix should not be used if the code relies on the previous behavior of nested Literals.\n\n
Why This Fix Works in Production
- Trigger: Nested Literals together with PEP-695 type statement are failed to produce json schema
- Mechanism: Nested Literals with PEP 695 type aliases were not being unpacked correctly in JSON schema generation
- Why the fix works: Recursively unpacks `Literal` values when using PEP 695 type aliases, addressing the issue of nested Literals not producing JSON schema correctly. (first fixed release: 2.10.4).
- 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
- Nested Literals with PEP 695 type aliases were not being unpacked correctly in JSON schema generation
- Production symptom (often without a traceback): Nested Literals together with PEP-695 type statement are failed to produce json schema
Proof / Evidence
- GitHub issue: #9269
- Fix PR: https://github.com/pydantic/pydantic/pull/11114
- First fixed release: 2.10.4
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.95
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.63
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@AlexanderPodorov, Thanks for the report. Seems like we don't fully support this syntax yet - PRs welcome with added support!”
“I've raised a discussion to clarify what should happen here”
Failure Signature (Search String)
- Nested Literals together with PEP-695 type statement are failed to produce json schema
- print(Model.model_json_schema())
Copy-friendly signature
Failure Signature
-----------------
Nested Literals together with PEP-695 type statement are failed to produce json schema
print(Model.model_json_schema())
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Nested Literals together with PEP-695 type statement are failed to produce json schema
print(Model.model_json_schema())
Minimal Reproduction
from typing import Literal
from pydantic import BaseModel
type TestType0 = Literal["test1", "test2"]
type TestType1 = Literal[TestType0, Literal["test3"]]
type TestType2 = Literal[Literal["test1", "test2"], Literal["test3"]]
# TestType1 does not work
# TestType2 works
class Model(BaseModel):
f: TestType1
print(Model.model_json_schema())
Environment
- Pydantic: 2
What Broke
JSON schema generation fails when using nested Literals with PEP 695 type aliases.
Why It Broke
Nested Literals with PEP 695 type aliases were not being unpacked correctly in JSON schema generation
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.10.4
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/11114
First fixed release: 2.10.4
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if the code relies on the previous behavior of nested Literals.
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.10.4 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.