The Fix
pip install pydantic==2.12
Based on closed pydantic/pydantic issue #11446 · 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%.
@@ -1115,28 +1115,28 @@ def default_schema(self, schema: core_schema.WithDefaultSchema) -> JsonSchemaVal
# JSON Schemas viewed in serialization mode:
# TODO: improvements along with https://github.com/pydantic/pydantic/issues/8208
- if (
- self.mode == 'serialization'
- and (ser_schema := schema['schema'].get('serialization'))
import pydantic
from typing import Annotated
class Voltage:
def __init__(self, value: float):
self.__value = value
def get(self) -> float:
return self.__value
def __str__(self):
return f"{self.__value}V"
PydanticVoltage = Annotated[
Voltage,
pydantic.WithJsonSchema({"type": "number"}),
pydantic.PlainSerializer(lambda v: v.get()),
pydantic.BeforeValidator(lambda v: Voltage(v)),
]
class MyClass(pydantic.BaseModel):
model_config = pydantic.ConfigDict(arbitrary_types_allowed=True)
voltage: PydanticVoltage = Voltage(17)
print(MyClass.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.12\nWhen NOT to use: This fix should not be used if the serializer is not intended for JSON schema generation.\n\n
Why This Fix Works in Production
- Trigger: Serializer is not applied to json schema default value
- Mechanism: The serializer was not applied to the JSON schema default value due to improper fetching of the plain serializer function
- Why the fix works: Fixes the issue where the serializer was not applied to the JSON schema default value by properly fetching the plain serializer function during serialization mode. (first fixed release: 2.12).
- 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
- Shows up under Python 3.12 in real deployments (not just unit tests).
- The serializer was not applied to the JSON schema default value due to improper fetching of the plain serializer function
- Production symptom (often without a traceback): Serializer is not applied to json schema default value
Proof / Evidence
- GitHub issue: #11446
- Fix PR: https://github.com/pydantic/pydantic/pull/11721
- First fixed release: 2.12
- 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.55
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: 2.12
- Mode: fixed_only
- Outcome: ok
Logs
{'properties': {'voltage': {'title': 'Voltage', 'type': 'number'}}, 'title': 'MyClass', 'type': 'object'}
\n\n[stderr]\n/tmp/ss-exec-e1c1ljyy/site/pydantic/json_schema.py:2442: PydanticJsonSchemaWarning: Default value 17V is not JSON serializable; excluding default from JSON schema [non-serializable-default]
warnings.warn(message, PydanticJsonSchemaWarning)
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Assuming you want to use mode='serialization', this will be fixed in 2.12. In validation mode, you will need to specify the json_schema_input_type on your validator.”
“Hi @Horrih, First off, thanks for the clean and reproducible example - makes things super easy for us!! Admittedly, the solution here is frustrating”
“That's great news, thank you all for your selfless work !”
Failure Signature (Search String)
- Serializer is not applied to json schema default value
- I have an external class, Voltage, I cannot modify.
Copy-friendly signature
Failure Signature
-----------------
Serializer is not applied to json schema default value
I have an external class, Voltage, I cannot modify.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Serializer is not applied to json schema default value
I have an external class, Voltage, I cannot modify.
Minimal Reproduction
import pydantic
from typing import Annotated
class Voltage:
def __init__(self, value: float):
self.__value = value
def get(self) -> float:
return self.__value
def __str__(self):
return f"{self.__value}V"
PydanticVoltage = Annotated[
Voltage,
pydantic.WithJsonSchema({"type": "number"}),
pydantic.PlainSerializer(lambda v: v.get()),
pydantic.BeforeValidator(lambda v: Voltage(v)),
]
class MyClass(pydantic.BaseModel):
model_config = pydantic.ConfigDict(arbitrary_types_allowed=True)
voltage: PydanticVoltage = Voltage(17)
print(MyClass.model_json_schema())
Environment
- Python: 3.12
- Pydantic: 2
What Broke
JSON schema generation fails with a warning about non-serializable default values.
Why It Broke
The serializer was not applied to the JSON schema default value due to improper fetching of the plain serializer function
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.12
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/11721
First fixed release: 2.12
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if the serializer is not intended for JSON schema generation.
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.12 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.