The Fix
pip install pydantic==1.10.19
Based on closed pydantic/pydantic issue #10434 · 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%.
@@ -127,6 +127,13 @@ def __get_pydantic_core_schema__(self, source_type: Any, handler: GetCoreSchemaH
else handler.generate_schema(self.json_schema_input_type)
)
+ # Try to resolve the original schema if required, because schema cleaning
+ # won't inline references in metadata:
+ if input_schema is not None:
from typing import Annotated
from pydantic import BaseModel, PlainSerializer, PlainValidator
class EmbeddedModel(BaseModel):
id: int
name: str
def val(v):
print(f'val {v}')
# in my real code I get fk_id and replace it to EmbeddedModel instance
return v
def ser(v):
print(f'ser {v}')
return v
class Model(BaseModel):
fk_id: Annotated[
EmbeddedModel,
PlainSerializer(ser, return_type=EmbeddedModel),
PlainValidator(val, json_schema_input_type=EmbeddedModel),
]
# m = Model.validate_model({fk_id:1})
m = Model(fk_id=EmbeddedModel(id=1, name='my embed'))
print(m.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==1.10.19\nWhen NOT to use: Do not use this fix if your model relies on complex nested references that cannot be resolved.\n\n
Why This Fix Works in Production
- Trigger: Plain serializer and validator in Annotated does not work with pydantic model
- Mechanism: The schema generation fails due to unresolved references in the PlainSerializer and PlainValidator
- Why the fix works: Inlines references when generating schema for json_schema_input_type, resolving issues with JSON Schema generation. (first fixed release: 1.10.19).
- 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 schema generation fails due to unresolved references in the PlainSerializer and PlainValidator
- Production symptom (often without a traceback): Plain serializer and validator in Annotated does not work with pydantic model
Proof / Evidence
- GitHub issue: #10434
- Fix PR: https://github.com/pydantic/pydantic/pull/10439
- First fixed release: 1.10.19
- 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.52
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“### Initial Checks - [X] I confirm that I'm using Pydantic V2 ### Description I'm trying to use plain validator as hook to do some transformation for example return object instead of id. In example below i just define simplified example tha”
Failure Signature (Search String)
- Plain serializer and validator in Annotated does not work with pydantic model
- PlainValidator(val, json_schema_input_type=EmbeddedModel),
Copy-friendly signature
Failure Signature
-----------------
Plain serializer and validator in Annotated does not work with pydantic model
PlainValidator(val, json_schema_input_type=EmbeddedModel),
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Plain serializer and validator in Annotated does not work with pydantic model
PlainValidator(val, json_schema_input_type=EmbeddedModel),
Minimal Reproduction
from typing import Annotated
from pydantic import BaseModel, PlainSerializer, PlainValidator
class EmbeddedModel(BaseModel):
id: int
name: str
def val(v):
print(f'val {v}')
# in my real code I get fk_id and replace it to EmbeddedModel instance
return v
def ser(v):
print(f'ser {v}')
return v
class Model(BaseModel):
fk_id: Annotated[
EmbeddedModel,
PlainSerializer(ser, return_type=EmbeddedModel),
PlainValidator(val, json_schema_input_type=EmbeddedModel),
]
# m = Model.validate_model({fk_id:1})
m = Model(fk_id=EmbeddedModel(id=1, name='my embed'))
print(m.model_json_schema())
Environment
- Python: 3.12
- Pydantic: 2
What Broke
Users experience serialization errors leading to application crashes.
Why It Broke
The schema generation fails due to unresolved references in the PlainSerializer and PlainValidator
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==1.10.19
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/10439
First fixed release: 1.10.19
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if your model relies on complex nested references that cannot be resolved.
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 |
|---|---|
| 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.