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%.
@@ -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
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")
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
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).
- 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
- GitHub issue: #11042
- Fix PR: https://github.com/pydantic/pydantic/pull/11184
- First fixed release: 1.10.20
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.95
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.52
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.”
“@commonism, What pattern (like, verbally), are you trying to match?”
“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…”
“As I'm with the client side of OpenAPI, the regex is user-supplied as part of the OpenAPI description document”
Failure Signature (Search String)
- return SchemaValidator(schema, config)
Error Message
Stack trace
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
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
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.
When NOT to Use This Fix
- This fix is not applicable if the regex patterns are not compatible with the expected engine.
Verify Fix
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
| Version | Status |
|---|---|
| 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.