Jump to solution
Verify

The Fix

pip install pydantic==1.10.16

Based on closed pydantic/pydantic issue #9525 · 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
@@ -1053,6 +1053,19 @@ def default_schema(self, schema: core_schema.WithDefaultSchema) -> JsonSchemaVal # return json_schema + # we reflect the application of custom plain, no-info serializers to defaults for + # json schemas viewed in serialization mode + # TODO: improvements along with https://github.com/pydantic/pydantic/issues/8208
repro.py
from typing import Annotated, Any from pydantic import BaseModel, model_validator from pydantic.functional_validators import ModelWrapValidatorHandler from typing_extensions import Self # Pretend this is some third-party class # we can't modify directly... class Quantity: def __init__(self, value: float, unit: str): self.value = value self.unit = unit class QuantityAnnotations(BaseModel): value: float unit: str @model_validator(mode="wrap") def _validate(value: Any, handler: ModelWrapValidatorHandler[Self]) -> Quantity: if isinstance(value, Quantity): return value validated = handler(value) if isinstance(validated, Quantity): return validated return Quantity(**dict(validated)) QuantityType = Annotated[Quantity, QuantityAnnotations] class OurModel(BaseModel): quantity: QuantityType = Quantity(value=0.0, unit='m') model_instance = OurModel() # This works fine... print(model_instance.model_dump_json()) # {"quantity":{"value":0.0,"unit":"m"}} # But this throws a warning about being unable to JSON serialize the # same default value it just dumped successfully above. OurModel.model_json_schema() # ...lib/python3.10/site-packages/pydantic/json_schema.py:2158: PydanticJsonSchemaWarning: # Default value <__main__.Quantity object at 0x75fcccab1960> is not JSON serializable; # excluding default from JSON schema [non-serializable-default]
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==1.10.16\nWhen NOT to use: This fix should not be used if the model relies on non-serializable default values.\n\nOption C — Workaround\nthat lets you customize your schema for such types, for now. I've slimmed down an example below from actual library code I've written. In this example, I want the schema to have defaults for `pathlib.Path` objects that look like the `pathlib.Path.as_posix()` stringified output of that path. Never mind that round-tripping of string paths back from a file isn't shown in the code example.\nWhen NOT to use: This fix should not be used if the model relies on non-serializable default values.\n\n

Why This Fix Works in Production

  • Trigger: `model_json_schema()` fails to include annotated third-party types: "Default value is not JSON serializable [non-serializable-default]"
  • Mechanism: The model_json_schema() function fails to serialize default values of annotated third-party types
  • Why the fix works: Addresses the issue where model_json_schema() fails to include annotated third-party types by applying custom serializers to defaults for JSON schemas viewed in serialization mode. (first fixed release: 1.10.16).
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.10 in real deployments (not just unit tests).
  • The model_json_schema() function fails to serialize default values of annotated third-party types
  • Production symptom (often without a traceback): `model_json_schema()` fails to include annotated third-party types: "Default value is not JSON serializable [non-serializable-default]"

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“astropy.Quantity in my case, but yes, the situation is similar. Users prefer/expect to have vanilla quantity objects, not unusual subclasses or annotated types.”
@bjmc · 2024-10-09 · source
“My suspicion here is that core schema logic supplied by annotated metadata isn't being used during json schema generation, but I haven't looked into the…”
@sydney-runkle · 2024-06-19 · source
“@blakeNaccarato If understand your code correctly, you're silencing/ignoring the "non-serializable-default" warning, and then modifying the schema directly to re-add a stringified version of the pathlib.Path…”
@bjmc · 2024-10-09 · source
“You are using Pydantic models as annotated metadata to validate a third-party type, which isn't a supported pattern”
@Viicos · 2025-04-08 · source

Failure Signature (Search String)

  • `model_json_schema()` fails to include annotated third-party types: "Default value is not JSON serializable [non-serializable-default]"
  • ... and the defaults are excluded from the resulting schema.
Copy-friendly signature
signature.txt
Failure Signature ----------------- `model_json_schema()` fails to include annotated third-party types: "Default value is not JSON serializable [non-serializable-default]" ... and the defaults are excluded from the resulting schema.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- `model_json_schema()` fails to include annotated third-party types: "Default value is not JSON serializable [non-serializable-default]" ... and the defaults are excluded from the resulting schema.

Minimal Reproduction

repro.py
from typing import Annotated, Any from pydantic import BaseModel, model_validator from pydantic.functional_validators import ModelWrapValidatorHandler from typing_extensions import Self # Pretend this is some third-party class # we can't modify directly... class Quantity: def __init__(self, value: float, unit: str): self.value = value self.unit = unit class QuantityAnnotations(BaseModel): value: float unit: str @model_validator(mode="wrap") def _validate(value: Any, handler: ModelWrapValidatorHandler[Self]) -> Quantity: if isinstance(value, Quantity): return value validated = handler(value) if isinstance(validated, Quantity): return validated return Quantity(**dict(validated)) QuantityType = Annotated[Quantity, QuantityAnnotations] class OurModel(BaseModel): quantity: QuantityType = Quantity(value=0.0, unit='m') model_instance = OurModel() # This works fine... print(model_instance.model_dump_json()) # {"quantity":{"value":0.0,"unit":"m"}} # But this throws a warning about being unable to JSON serialize the # same default value it just dumped successfully above. OurModel.model_json_schema() # ...lib/python3.10/site-packages/pydantic/json_schema.py:2158: PydanticJsonSchemaWarning: # Default value <__main__.Quantity object at 0x75fcccab1960> is not JSON serializable; # excluding default from JSON schema [non-serializable-default]

Environment

  • Python: 3.10
  • Pydantic: 2

What Broke

Default values are excluded from the JSON schema, leading to incomplete schema generation.

Why It Broke

The model_json_schema() function fails to serialize default values of annotated third-party types

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install pydantic==1.10.16

When NOT to use: This fix should not be used if the model relies on non-serializable default values.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Option C — Workaround Temporary workaround

that lets you customize your schema for such types, for now. I've slimmed down an example below from actual library code I've written. In this example, I want the schema to have defaults for `pathlib.Path` objects that look like the `pathlib.Path.as_posix()` stringified output of that path. Never mind that round-tripping of string paths back from a file isn't shown in the code example.

When NOT to use: This fix should not be used if the model relies on non-serializable default values.

Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.

Fix reference: https://github.com/pydantic/pydantic/pull/9624

First fixed release: 1.10.16

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 model relies on non-serializable default values.

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
1.10.16 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.