Jump to solution
Verify

The Fix

pip install pydantic==1.10.20

Based on closed pydantic/pydantic issue #11042 · 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
@@ -11,7 +11,7 @@ from functools import lru_cache, partial from types import FunctionType -from typing import Any, Callable, Generic, Literal, NoReturn, TypeVar, cast +from typing import Any, Callable, Generic, Literal, NoReturn, cast
repro.py
from typing import Annotated, Dict from pydantic import BaseModel, constr, Field, RootModel, create_model PATTERN = r"(^Passphrase:[ ^[ !#-~]+$)" class A(BaseModel): v: str = constr(pattern=PATTERN) assert A.model_validate({"v": "Passphrase: test"}) class B(BaseModel): model_config = dict(regex_engine="python-re") v: str = Field(pattern=PATTERN) assert B.model_validate({"v": "Passphrase: test"}) class GoodModel(RootModel): model_config = dict(regex_engine="python-re") C = Annotated[str, Field(pattern=PATTERN)] Cx = create_model("C", __base__=(GoodModel[C], )) # raises on pydantic >= 2.10.0b1 assert Cx.model_validate("Passphrase: test")
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.20\nWhen NOT to use: This fix is not applicable if the regex patterns are not compatible with the expected engine.\n\n

Why This Fix Works in Production

  • Trigger: return SchemaValidator(schema, config)
  • Mechanism: The regex engine was strict even with python-re configured due to a custom MRO implementation
  • Why the fix works: Removes the custom MRO implementation of Pydantic models, which is no longer necessary. (first fixed release: 1.10.20).
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

  • Shows up under Python 3.12 in real deployments (not just unit tests).
  • The regex engine was strict even with python-re configured due to a custom MRO implementation
  • Surfaces as: return SchemaValidator(schema, config)

Proof / Evidence

Discussion

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

“Hi, Thanks for raising this issue. I'll take a look at this for v2.10.4.”
@sydney-runkle · 2024-12-10 · source
“@commonism, What pattern (like, verbally), are you trying to match?”
@sydney-runkle · 2024-12-18 · source
“I'm not actually convinced this is a regression yet, going to go ahead and release v2.10.4 without a fix here, but happy to investigate this…”
@sydney-runkle · 2024-12-18 · source
“As I'm with the client side of OpenAPI, the regex is user-supplied as part of the OpenAPI description document”
@commonism · 2024-12-19 · source

Failure Signature (Search String)

  • return SchemaValidator(schema, config)

Error Message

Stack trace
error.txt
Error Message ------------- return SchemaValidator(schema, config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pydantic_core._pydantic_core.SchemaError: Error building "model" validator: SchemaError: Error building "str" validator: SchemaError: regex parse error: (^Passphrase:[ ^[ !#-~]+$)

Minimal Reproduction

repro.py
from typing import Annotated, Dict from pydantic import BaseModel, constr, Field, RootModel, create_model PATTERN = r"(^Passphrase:[ ^[ !#-~]+$)" class A(BaseModel): v: str = constr(pattern=PATTERN) assert A.model_validate({"v": "Passphrase: test"}) class B(BaseModel): model_config = dict(regex_engine="python-re") v: str = Field(pattern=PATTERN) assert B.model_validate({"v": "Passphrase: test"}) class GoodModel(RootModel): model_config = dict(regex_engine="python-re") C = Annotated[str, Field(pattern=PATTERN)] Cx = create_model("C", __base__=(GoodModel[C], )) # raises on pydantic >= 2.10.0b1 assert Cx.model_validate("Passphrase: test")

Environment

  • Python: 3.12
  • Pydantic: 2

What Broke

Validation errors occurred when using certain regex patterns in RootModel.

Why It Broke

The regex engine was strict even with python-re configured due to a custom MRO implementation

Fix Options (Details)

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

pip install pydantic==1.10.20

When NOT to use: This fix is not applicable if the regex patterns are not compatible with the expected engine.

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

First fixed release: 1.10.20

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

  • This fix is not applicable if the regex patterns are not compatible with the expected engine.

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

Related Issues

No related fixes found.

Sources

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