The Fix
pip install pydantic==1.10.15
Based on closed pydantic/pydantic issue #8905 · 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%.
@@ -732,24 +732,22 @@ def literal_schema(self, schema: core_schema.LiteralSchema) -> JsonSchemaValue:
expected = [to_jsonable_python(v) for v in expected]
+ result: dict[str, Any] = {'enum': expected}
if len(expected) == 1:
- return {'const': expected[0]}
from pydantic import BaseModel
from typing import Literal
class Foo(BaseModel):
bar: Literal["Bar"] = 'Bar'
baz: Literal[None] = 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==1.10.15\nWhen NOT to use: This fix should not be applied if backward compatibility with existing JSON schemas is a concern.\n\n
Why This Fix Works in Production
- Trigger: `Literal` annotation does not render type to json-schema
- Mechanism: The JSON schema generation for single item literals did not include type information
- Why the fix works: Adds enum and type to the JSON schema for single item literals, addressing the issue where Literal annotations do not render types correctly in the JSON schema. (first fixed release: 1.10.15).
- 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 for single item literals did not include type information
- Production symptom (often without a traceback): `Literal` annotation does not render type to json-schema
Proof / Evidence
- GitHub issue: #8905
- Fix PR: https://github.com/pydantic/pydantic/pull/8944
- First fixed release: 1.10.15
- 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.68
Verified Execution
We executed the runnable minimal repro in a temporary environment and captured exit codes + logs.
- Status: PASS
- Ran: 2026-02-11T16:52:29Z
- Package: pydantic
- Fixed: 1.10.15
- Mode: fixed_only
- Outcome: ok
Logs
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Ah, now I understand”
“@WillDaSilva does the following not work for you? More generally though, I think we should do a better job of handling single-item literals as I…”
“@dmontagu That works for when the list of possible values is static (i.e. hard-coded), but when you have the list of strings as a variable…”
“@bruno-f-cruz does the change proposed in #8944 address your issue, or do you otherwise have any problems with it? It goes a bit farther than…”
Failure Signature (Search String)
- `Literal` annotation does not render type to json-schema
- The output json-schema model loses the typing of the variable used for the literal. I.e.:
Copy-friendly signature
Failure Signature
-----------------
`Literal` annotation does not render type to json-schema
The output json-schema model loses the typing of the variable used for the literal. I.e.:
Error Message
Signature-only (no traceback captured)
Error Message
-------------
`Literal` annotation does not render type to json-schema
The output json-schema model loses the typing of the variable used for the literal. I.e.:
Minimal Reproduction
from pydantic import BaseModel
from typing import Literal
class Foo(BaseModel):
bar: Literal["Bar"] = 'Bar'
baz: Literal[None] = None
Environment
- Pydantic: 2
What Broke
JSON schemas generated from models with Literal types lacked proper type annotations, causing integration issues.
Why It Broke
The JSON schema generation for single item literals did not include type information
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==1.10.15
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/8944
First fixed release: 1.10.15
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if backward compatibility with existing JSON schemas is a concern.
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 |
|---|---|
| 1.10.15 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.