Jump to solution
Verify

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%.

Jump to Verify Open PR/Commit
@@ -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'))
repro.py
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())
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
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).
Production impact:
  • 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

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
affected (exit=None)
fixed (exit=0)
{'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.”
@Viicos · 2025-04-08 · confirmation · source
“Hi @Horrih, First off, thanks for the clean and reproducible example - makes things super easy for us!! Admittedly, the solution here is frustrating”
@sydney-runkle · 2025-02-17 · source
“That's great news, thank you all for your selfless work !”
@Horrih · 2025-04-09 · source

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
signature.txt
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.txt
Error Message ------------- Serializer is not applied to json schema default value I have an external class, Voltage, I cannot modify.

Minimal Reproduction

repro.py
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

When NOT to use: This fix should not be used if the serializer is not intended for JSON schema generation.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be used if the serializer is not intended for JSON schema generation.

Verify Fix

verify
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

VersionStatus
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.