Jump to solution
Verify

The Fix

pip install pydantic==2.8.1

Based on closed pydantic/pydantic issue #9210 · PR/commit linked

Jump to Verify Open PR/Commit
@@ -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.
repro.py
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())
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.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

Discussion

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

“@Mark90, Thanks for reporting this”
@sydney-runkle · 2024-04-11 · source
“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 · 2024-06-10 · source
“@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 · 2024-04-16 · source
“@nix010, Great question”
@sydney-runkle · 2024-06-09 · source

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
signature.txt
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.txt
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

repro.py
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

When NOT to use: Do not use this fix if you rely on the previous behavior of BaseModel not merging json_schema_extra.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

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

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