Jump to solution
Verify

The Fix

pip install pydantic==2.12.0

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

Jump to Verify Open PR/Commit
@@ -182,7 +182,8 @@ def apply_known_metadata(annotation: Any, schema: CoreSchema) -> CoreSchema | No Raises: - PydanticCustomError: If `Predicate` fails. + RuntimeError: If a constraint can't be applied to a specific schema type. + ValueError: If an unknown constraint is encountered.
repro.py
from pydantic import TypeAdapter, ValidationError from pydantic.experimental.pipeline import validate_as from typing import Annotated from functools import partial incr1 = partial(lambda x, incr: x == incr, incr=1) ta_str_to_int = TypeAdapter[int](Annotated[int, validate_as(int).predicate(incr1)]) assert ta_str_to_int.validate_python(1) == 1 try: ta_str_to_int.validate_python(2) except ValidationError: print("This is expected since 1 != 2")
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.12.0\nWhen NOT to use: Do not use this fix if your code relies on lambda functions for predicate validation.\n\n

Why This Fix Works in Production

  • Trigger: assert ta_str_to_int.validate_python(1) == 1
  • Mechanism: Fixes an issue with using functools.partial in the pipelines API by not relying on inferring names from lambda definitions.
  • Why the fix works: Fixes an issue with using functools.partial in the pipelines API by not relying on inferring names from lambda definitions. (first fixed release: 2.12.0).

Why This Breaks in Prod

  • Production symptom (often without a traceback): from pydantic import TypeAdapter, ValidationError

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 I ran into an issue when using the new pipelines API in combination with functools.partial as predicate. This check can also be done by using a lambda, but since”
Issue thread · issue description · source

Failure Signature (Search String)

  • assert ta_str_to_int.validate_python(1) == 1
Copy-friendly signature
signature.txt
Failure Signature ----------------- from pydantic import TypeAdapter, ValidationError assert ta_str_to_int.validate_python(1) == 1

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- from pydantic import TypeAdapter, ValidationError assert ta_str_to_int.validate_python(1) == 1

Minimal Reproduction

repro.py
from pydantic import TypeAdapter, ValidationError from pydantic.experimental.pipeline import validate_as from typing import Annotated from functools import partial incr1 = partial(lambda x, incr: x == incr, incr=1) ta_str_to_int = TypeAdapter[int](Annotated[int, validate_as(int).predicate(incr1)]) assert ta_str_to_int.validate_python(1) == 1 try: ta_str_to_int.validate_python(2) except ValidationError: print("This is expected since 1 != 2")

Environment

  • Pydantic: 2

What Broke

Users experienced validation errors when using partial functions as predicates in the pipelines API.

Fix Options (Details)

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

pip install pydantic==2.12.0

When NOT to use: Do not use this fix if your code relies on lambda functions for predicate validation.

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

First fixed release: 2.12.0

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 your code relies on lambda functions for predicate validation.

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

Related Issues

No related fixes found.

Sources

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