The Fix
pip install pydantic==2.8.1
Based on closed pydantic/pydantic issue #9210 · PR/commit linked
@@ -617,6 +617,78 @@ print(json.dumps(Model.model_json_schema(), indent=2))
```
+#### Merging `json_schema_extra`
+
+Starting in v2.9, Pydantic merges `json_schema_extra` dictionaries from annotated types.
from pprint import pprint
from typing import Annotated
from pydantic import TypeAdapter, BaseModel, Field
MyStr = Annotated[
str,
Field(json_schema_extra={'key1': 'value1'}),
Field(json_schema_extra={'key2': 'value2'})
]
class Foo(BaseModel):
v: MyStr
print("BaseModel.model_json_schema")
pprint(Foo.model_json_schema())
print("TypeAdapter().json_schema")
pprint(TypeAdapter(MyStr).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==2.8.1\nWhen NOT to use: Do not use this fix if you rely on the previous behavior of BaseModel not merging json_schema_extra.\n\n
Why This Fix Works in Production
- Trigger: Difference between TypeAdapter().json_schema and BaseModel.model_json_schema
- Mechanism: TypeAdapter merges json_schema_extra fields differently than BaseModel, causing inconsistencies
- Why the fix works: Merges `json_schema_extra` dictionaries from annotated types, resolving inconsistencies between `BaseModel` and `TypeAdapter` behavior. (first fixed release: 2.8.1).
Why This Breaks in Prod
- Shows up under Python 3.12 in real deployments (not just unit tests).
- TypeAdapter merges json_schema_extra fields differently than BaseModel, causing inconsistencies
- Production symptom (often without a traceback): Difference between TypeAdapter().json_schema and BaseModel.model_json_schema
Proof / Evidence
- GitHub issue: #9210
- Fix PR: https://github.com/pydantic/pydantic/pull/9792
- First fixed release: 2.8.1
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.60
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@Mark90, Thanks for reporting this”
“Alright, let's go with the TypeAdapter approach. This should also fix #7686 that I've mentioned above. We'll want to document this as a breaking change,…”
“@sydney-runkle While working on the issue I found something that I want to clarify. Result Note that key2 is set by a callable json_schema_extra -…”
“@nix010, Great question”
Failure Signature (Search String)
- Difference between TypeAdapter().json_schema and BaseModel.model_json_schema
- When presented with an annotated type with multiple `Field` objects that set `json_schema_extra`, `TypeAdapter` seems to combine them whereas `BaseModel` does not.
Copy-friendly signature
Failure Signature
-----------------
Difference between TypeAdapter().json_schema and BaseModel.model_json_schema
When presented with an annotated type with multiple `Field` objects that set `json_schema_extra`, `TypeAdapter` seems to combine them whereas `BaseModel` does not.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Difference between TypeAdapter().json_schema and BaseModel.model_json_schema
When presented with an annotated type with multiple `Field` objects that set `json_schema_extra`, `TypeAdapter` seems to combine them whereas `BaseModel` does not.
Minimal Reproduction
from pprint import pprint
from typing import Annotated
from pydantic import TypeAdapter, BaseModel, Field
MyStr = Annotated[
str,
Field(json_schema_extra={'key1': 'value1'}),
Field(json_schema_extra={'key2': 'value2'})
]
class Foo(BaseModel):
v: MyStr
print("BaseModel.model_json_schema")
pprint(Foo.model_json_schema())
print("TypeAdapter().json_schema")
pprint(TypeAdapter(MyStr).json_schema())
Environment
- Python: 3.12
- Pydantic: 2
What Broke
Users experience unexpected behavior when using TypeAdapter and BaseModel for json schema generation.
Why It Broke
TypeAdapter merges json_schema_extra fields differently than BaseModel, causing inconsistencies
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.8.1
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/9792
First fixed release: 2.8.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if you rely on the previous behavior of BaseModel not merging json_schema_extra.
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 |
|---|---|
| 2.8.1 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.