Jump to solution
Verify

The Fix

pip install pydantic==2.11.8

Based on closed pydantic/pydantic issue #11930 · 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
@@ -3074,9 +3074,11 @@ def __get_pydantic_core_schema__(self, source_type: Any, handler: GetCoreSchemaH else: original_schema = handler(source_type) - return self._convert_schema(original_schema) + return self._convert_schema(original_schema, handler)
repro.py
from typing import Annotated, Any, Literal from pydantic import BaseModel, Discriminator, Tag class Pie(BaseModel): time_to_cook: int num_ingredients: int class ApplePie(Pie): fruit: Literal['apple'] = 'apple' class PumpkinPie(Pie): filling: Literal['pumpkin'] = 'pumpkin' def get_discriminator_value(v: Any) -> str: print("I'm discriminating!") if isinstance(v, dict): return v.get('fruit', v.get('filling')) return getattr(v, 'fruit', getattr(v, 'filling', None)) # This works type Dessert = Annotated[ (Annotated[ApplePie, Tag('apple')] | Annotated[PumpkinPie, Tag('pumpkin')]), Discriminator(get_discriminator_value), ] class ThanksgivingDinner(BaseModel): dessert: Dessert # This doesn't work # Works if using implicit alias: TaggedApplePie = Annotated[ApplePie, Tag('apple')] type TaggedApplePie = Annotated[ApplePie, Tag('apple')] class ThanksgivingDinnerSeconds(BaseModel): dessert: Annotated[ (TaggedApplePie | Annotated[PumpkinPie, Tag('pumpkin')]), Discriminator(get_discriminator_value), ]
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.11.8\nWhen NOT to use: Do not apply this fix if using non-nested type aliases.\n\n

Why This Fix Works in Production

  • Trigger: PydanticUserError: `Tag` not provided for choice {'type': 'definition-ref', 'schema_ref': '__main__.TaggedApplePie:140478632382272'} used with `Discriminator`
  • Mechanism: Pydantic fails to extract Tags from nested named type aliases during model construction
  • Why the fix works: Allow callable discriminator to be applied on PEP 695 type aliases, fixing the issue with tags not being extracted from nested named type aliases. (first fixed release: 2.11.8).
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

  • Pydantic fails to extract Tags from nested named type aliases during model construction
  • Surfaces as: PydanticUserError: `Tag` not provided for choice {'type': 'definition-ref', 'schema_ref': '__main__.TaggedApplePie:140478632382272'} used with `Discriminator`

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 During model construction, pydantic doesn't pull Tags from inner named type alias annotations, but will do it if the entire union is a named type alias, as seen i”
Issue thread · issue description · source

Failure Signature (Search String)

  • PydanticUserError: `Tag` not provided for choice {'type': 'definition-ref', 'schema_ref': '__main__.TaggedApplePie:140478632382272'} used with `Discriminator`

Error Message

Stack trace
error.txt
Error Message ------------- PydanticUserError: `Tag` not provided for choice {'type': 'definition-ref', 'schema_ref': '__main__.TaggedApplePie:140478632382272'} used with `Discriminator`

Minimal Reproduction

repro.py
from typing import Annotated, Any, Literal from pydantic import BaseModel, Discriminator, Tag class Pie(BaseModel): time_to_cook: int num_ingredients: int class ApplePie(Pie): fruit: Literal['apple'] = 'apple' class PumpkinPie(Pie): filling: Literal['pumpkin'] = 'pumpkin' def get_discriminator_value(v: Any) -> str: print("I'm discriminating!") if isinstance(v, dict): return v.get('fruit', v.get('filling')) return getattr(v, 'fruit', getattr(v, 'filling', None)) # This works type Dessert = Annotated[ (Annotated[ApplePie, Tag('apple')] | Annotated[PumpkinPie, Tag('pumpkin')]), Discriminator(get_discriminator_value), ] class ThanksgivingDinner(BaseModel): dessert: Dessert # This doesn't work # Works if using implicit alias: TaggedApplePie = Annotated[ApplePie, Tag('apple')] type TaggedApplePie = Annotated[ApplePie, Tag('apple')] class ThanksgivingDinnerSeconds(BaseModel): dessert: Annotated[ (TaggedApplePie | Annotated[PumpkinPie, Tag('pumpkin')]), Discriminator(get_discriminator_value), ]

Environment

  • Pydantic: 2

What Broke

Results in PydanticUserError when using Discriminator with nested type aliases.

Why It Broke

Pydantic fails to extract Tags from nested named type aliases during model construction

Fix Options (Details)

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

pip install pydantic==2.11.8

When NOT to use: Do not apply this fix if using non-nested type aliases.

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

First fixed release: 2.11.8

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 using non-nested type aliases.

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

Related Issues

No related fixes found.

Sources

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