Jump to solution
Verify

The Fix

pip install pydantic==1.10.19

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

Jump to Verify Open PR/Commit
@@ -1569,9 +1569,8 @@ def _generate_parameter_schema( field = FieldInfo.from_annotated_attribute(annotation, default) assert field.annotation is not None, 'field.annotation should not be None when generating a schema' - source_type, annotations = field.annotation, field.metadata with self.field_name_stack.push(name): - schema = self._apply_annotations(source_type, annotations)
repro.py
from typing import Literal, Union import pydantic from typing_extensions import Annotated class Cat(pydantic.BaseModel): type: Literal['cat'] = "cat" food: str class Dog(pydantic.BaseModel): type: Literal['dog'] = "dog" food: str Pet = Annotated[Union[Cat, Dog], pydantic.Field(discriminator="type")] class Test(pydantic.BaseModel): pet: Pet # test = Test(pet={"food": "fish"}) # raises validation error with "Unable to extract tag using discriminator 'type'" as expected @pydantic.validate_call def test_func(pet: Pet): return pet output = test_func(pet={"food": "fish"}) # Expect validation to fail here print(type(output)) # output is of type Cat
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 use this fix if the application relies on the previous validation behavior.\n\nOption C — Workaround\nis to write the discriminator explicitly in each annotation.\nWhen NOT to use: Do not use this fix if the application relies on the previous validation behavior.\n\n

Why This Fix Works in Production

  • Trigger: In [2]: test_func(pet={"food": "fish", "type": "cat"})
  • Mechanism: The `validate_call` function does not properly handle discriminated unions in `Annotated` types
  • Why the fix works: Fixes the issue where `validate_call` ignores the `Field` in `Annotated` types, specifically for discriminated unions. (first fixed release: 1.10.19).

Why This Breaks in Prod

  • Shows up under Python 3.8 in real deployments (not just unit tests).
  • The `validate_call` function does not properly handle discriminated unions in `Annotated` types
  • Surfaces as: In [2]: test_func(pet={"food": "fish", "type": "cat"})

Proof / Evidence

Discussion

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

“I believe your usage is correct and the underlying issue might be related to #10482. A possible workaround is to write the discriminator explicitly in…”
@mpkocher · 2024-10-08 · source
“Huh, very odd. Definitely misbehavior. Thanks for reporting this bug!”
@sydney-runkle · 2024-10-08 · source

Failure Signature (Search String)

  • In [2]: test_func(pet={"food": "fish", "type": "cat"})

Error Message

Stack trace
error.txt
Error Message ------------- In [2]: test_func(pet={"food": "fish", "type": "cat"}) Out[2]: Cat(type='cat', food='fish') In [3]: test_func(pet={"food": "fish", "type": "dog"}) Out[3]: Dog(type='dog', food='fish') In [4]: test_func(pet={"food": "fish", "type": "dragon"}) ValidationError: 2 validation errors for test_func pet.tagged-union[Cat] Input tag 'dragon' found using 'type' does not match any of the expected tags: 'cat' [type=union_tag_invalid, input_value={'food': 'fish', 'type': 'dragon'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.8/v/union_tag_invalid pet.tagged-union[Dog] Input tag 'dragon' found using 'type' does not match any of the expected tags: 'dog' [type=union_tag_invalid, input_value={'food': 'fish', 'type': 'dragon'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.8/v/union_tag_invalid In [5]: test_func(pet={"food": "fish"}) ValidationError: 2 validation errors for test_func pet.tagged-union[Cat] Unable to extract tag using discriminator 'type' [type=union_tag_not_found, input_value={'food': 'fish'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.8/v/union_tag_not_found pet.tagged-union[Dog] Unable to extract tag using discriminator 'type' [type=union_tag_not_found, input_value={'food': 'fish'}, input_type=dict] For further information visit https://errors.pydantic.dev/ ... (truncated) ...

Minimal Reproduction

repro.py
from typing import Literal, Union import pydantic from typing_extensions import Annotated class Cat(pydantic.BaseModel): type: Literal['cat'] = "cat" food: str class Dog(pydantic.BaseModel): type: Literal['dog'] = "dog" food: str Pet = Annotated[Union[Cat, Dog], pydantic.Field(discriminator="type")] class Test(pydantic.BaseModel): pet: Pet # test = Test(pet={"food": "fish"}) # raises validation error with "Unable to extract tag using discriminator 'type'" as expected @pydantic.validate_call def test_func(pet: Pet): return pet output = test_func(pet={"food": "fish"}) # Expect validation to fail here print(type(output)) # output is of type Cat

Environment

  • Python: 3.8
  • Pydantic: 2

What Broke

Validation fails unexpectedly, allowing incorrect types to pass through.

Why It Broke

The `validate_call` function does not properly handle discriminated unions in `Annotated` types

Fix Options (Details)

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

pip install pydantic==1.10.19

When NOT to use: Do not use this fix if the application relies on the previous validation behavior.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Option C — Workaround Temporary workaround

is to write the discriminator explicitly in each annotation.

When NOT to use: Do not use this fix if the application relies on the previous validation behavior.

Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.

Fix reference: https://github.com/pydantic/pydantic/pull/10610

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 use this fix if the application relies on the previous validation behavior.

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.