Jump to solution
Verify

The Fix

pip install pydantic==2.10.2

Based on closed pydantic/pydantic issue #9491 · 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
@@ -10,7 +10,7 @@ from typing import TYPE_CHECKING, Any, ClassVar -from pydantic_core import MultiHostHost, PydanticCustomError, core_schema +from pydantic_core import MultiHostHost, PydanticCustomError, SchemaSerializer, core_schema from pydantic_core import MultiHostUrl as _CoreMultiHostUrl
repro.py
from typing import Any from pydantic import BaseModel, SecretStr # Successful case class SuccessfulCase(BaseModel): some_value: SecretStr s = SuccessfulCase(some_value="1") print(f"Successful `model_dump_json` case: {s.model_dump_json()}") # Failing case class FailingCase(BaseModel): some_value: Any f = FailingCase(some_value=SecretStr("1")) f.model_dump_json() # fails with a pydantic_core._pydantic_core.PydanticSerializationError
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.10.2\nWhen NOT to use: Do not use this fix if your models do not contain SecretStr fields.\n\n

Why This Fix Works in Production

  • Trigger: f.model_dump_json() # fails with a pydantic_core._pydantic_core.PydanticSerializationError
  • Mechanism: Serialization fails for models with dynamic SecretStr fields due to missing serializer
  • Why the fix works: Supports serialization as any for `Secret` types and `Url` types, addressing serialization issues with `SecretStr` in Pydantic models. (first fixed release: 2.10.2).
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).
  • Serialization fails for models with dynamic SecretStr fields due to missing serializer
  • Production symptom (often without a traceback): f.model_dump_json() # fails with a pydantic_core._pydantic_core.PydanticSerializationError

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.10.2
  • Mode: fixed_only
  • Outcome: ok
Logs
affected (exit=None)
fixed (exit=0)
Successful `model_dump_json` case: {"some_value":"**********"}

Discussion

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

“Agreed with that opinion I think pretending they are or will be separate libraries would be a mistake. That said I do think we can…”
@adriangb · 2024-05-30 · repro detail · source
“@adriangb, I think that might be the right approach, and perhaps we should do that for other Pydantic types as well.”
@sydney-runkle · 2024-05-29 · source
“@davidhewitt, I recall us discussing the fact that having __pydantic_serializer__ checks in pydantic-core wasn't the best practice in terms of extremely tight coupling between the…”
@sydney-runkle · 2024-05-29 · source
“cc @bcdurak, I've opened a PR that could potentially fix this :)”
@sydney-runkle · 2024-11-22 · source

Failure Signature (Search String)

  • f.model_dump_json() # fails with a pydantic_core._pydantic_core.PydanticSerializationError
  • Can't we add a serializer to it?
Copy-friendly signature
signature.txt
Failure Signature ----------------- f.model_dump_json() # fails with a pydantic_core._pydantic_core.PydanticSerializationError Can't we add a serializer to it?

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- f.model_dump_json() # fails with a pydantic_core._pydantic_core.PydanticSerializationError Can't we add a serializer to it?

Minimal Reproduction

repro.py
from typing import Any from pydantic import BaseModel, SecretStr # Successful case class SuccessfulCase(BaseModel): some_value: SecretStr s = SuccessfulCase(some_value="1") print(f"Successful `model_dump_json` case: {s.model_dump_json()}") # Failing case class FailingCase(BaseModel): some_value: Any f = FailingCase(some_value=SecretStr("1")) f.model_dump_json() # fails with a pydantic_core._pydantic_core.PydanticSerializationError

Environment

  • Python: 3.10
  • Pydantic: 2

What Broke

API responses fail with internal server errors when serializing models containing SecretStr.

Why It Broke

Serialization fails for models with dynamic SecretStr fields due to missing serializer

Fix Options (Details)

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

pip install pydantic==2.10.2

When NOT to use: Do not use this fix if your models do not contain SecretStr fields.

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/10947

First fixed release: 2.10.2

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

  • Do not use this fix if your models do not contain SecretStr fields.

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.10.2 Fixed

Related Issues

No related fixes found.

Sources

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