Jump to solution
Verify

The Fix

pip install pydantic==1.10.19

Based on closed pydantic/pydantic issue #10443 · 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
@@ -458,6 +458,10 @@ def count_refs(s: core_schema.CoreSchema, recurse: Recurse) -> core_schema.CoreS current_recursion_ref_count[ref] += 1 + if 'serialization' in s: + # Even though this is a `'definition-ref'` schema, there might + # be more references inside the serialization schema:
repro.py
from typing import Annotated from pydantic import BaseModel, PlainSerializer class Sub(BaseModel): pass class Model(BaseModel): sub: Annotated[ Sub, PlainSerializer(lambda v: v, return_type=Sub), ] # pydantic_core._pydantic_core.SchemaError: Definitions error: definition `__main__.Sub:97954749220704` was never filled
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.19\nWhen NOT to use: Do not apply this fix if the serialization schema is expected to contain additional references.\n\n

Why This Fix Works in Production

  • Trigger: Schema generation error when serialization schema holds a reference
  • Mechanism: The schema generation error occurs due to unexpected serialization keys in the definition-ref schema
  • Why the fix works: Fix schema generation error when serialization schema holds references. (first fixed release: 1.10.19).
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

  • The schema generation error occurs due to unexpected serialization keys in the definition-ref schema
  • Production symptom (often without a traceback): Schema generation error when serialization schema holds a reference

Proof / Evidence

Discussion

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

“### Initial Checks - [X] I confirm that I'm using Pydantic V2 ### Description The following code currently raises: The reason is that, before schema cleaning, the core schema looks like: Which is quite unusual: the 'definition-ref' schema t”
Issue thread · issue description · source

Failure Signature (Search String)

  • Schema generation error when serialization schema holds a reference
  • The reason is that, before schema cleaning, the core schema looks like:
Copy-friendly signature
signature.txt
Failure Signature ----------------- Schema generation error when serialization schema holds a reference The reason is that, before schema cleaning, the core schema looks like:

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Schema generation error when serialization schema holds a reference The reason is that, before schema cleaning, the core schema looks like:

Minimal Reproduction

repro.py
from typing import Annotated from pydantic import BaseModel, PlainSerializer class Sub(BaseModel): pass class Model(BaseModel): sub: Annotated[ Sub, PlainSerializer(lambda v: v, return_type=Sub), ] # pydantic_core._pydantic_core.SchemaError: Definitions error: definition `__main__.Sub:97954749220704` was never filled

Environment

  • Pydantic: 2

What Broke

Users experience schema generation failures leading to application crashes during model serialization.

Why It Broke

The schema generation error occurs due to unexpected serialization keys in the definition-ref schema

Fix Options (Details)

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

pip install pydantic==1.10.19

When NOT to use: Do not apply this fix if the serialization schema is expected to contain additional references.

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

First fixed release: 1.10.19

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 apply this fix if the serialization schema is expected to contain additional references.

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

Related Issues

No related fixes found.

Sources

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