The Fix
pip install pydantic==1.10.19
Based on closed pydantic/pydantic issue #10498 · 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%.
@@ -201,7 +201,7 @@ def apply_known_metadata(annotation: Any, schema: CoreSchema) -> CoreSchema | No
import annotated_types as at
- from ._validators import forbid_inf_nan_check, get_constraint_validator
+ from ._validators import NUMERIC_VALIDATOR_LOOKUP, forbid_inf_nan_check
import decimal
from pydantic import BaseModel, Field, BeforeValidator
from typing import Annotated
DecimalAnnotation = Annotated[decimal.Decimal, BeforeValidator(lambda v: v)]
class ExampleSchema(BaseModel):
example_value: DecimalAnnotation | None = Field(max_digits=10, decimal_places=4)
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.19\nWhen NOT to use: This fix should not be used if the application relies on previous behavior of Pydantic 2.8.\n\n
Why This Fix Works in Production
- Trigger: `Optional[Decimal]` with field constraints error: Unable to apply constraint 'max_digits' to schema of type 'function-after'
- Mechanism: The Pydantic library fails to apply 'max_digits' and 'decimal_places' constraints to Decimal fields when using annotations
- Why the fix works: Adds Python validators for decimal constraints, specifically addressing issues with applying 'max_digits' and 'decimal_places' constraints to annotated fields in Pydantic. (first fixed release: 1.10.19).
- 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
- The Pydantic library fails to apply 'max_digits' and 'decimal_places' constraints to Decimal fields when using annotations
- Production symptom (often without a traceback): `Optional[Decimal]` with field constraints error: Unable to apply constraint 'max_digits' to schema of type 'function-after'
Proof / Evidence
- GitHub issue: #10498
- Fix PR: https://github.com/pydantic/pydantic/pull/10506
- First fixed release: 1.10.19
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.60
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@JoelRaymann, Could you please send a reproducible example (with imports, etc)? Happy to look into this for you.”
“@sydney-runkle So based on your suggestion, I should do this right: Am I right? or am I missing something?”
“Ok”
“Re 1: Because of https://github.com/pydantic/pydantic/blob/728d3d9f41c480d35c1188f56cc360bae93f0543/pydantic/fields.py#L371”
Failure Signature (Search String)
- `Optional[Decimal]` with field constraints error: Unable to apply constraint 'max_digits' to schema of type 'function-after'
- Still, nothing works. I am still getting the `RuntimeError: Unable to apply constraint 'max_digits' to schema of type 'function-after'`.
Copy-friendly signature
Failure Signature
-----------------
`Optional[Decimal]` with field constraints error: Unable to apply constraint 'max_digits' to schema of type 'function-after'
Still, nothing works. I am still getting the `RuntimeError: Unable to apply constraint 'max_digits' to schema of type 'function-after'`.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
`Optional[Decimal]` with field constraints error: Unable to apply constraint 'max_digits' to schema of type 'function-after'
Still, nothing works. I am still getting the `RuntimeError: Unable to apply constraint 'max_digits' to schema of type 'function-after'`.
Minimal Reproduction
import decimal
from pydantic import BaseModel, Field, BeforeValidator
from typing import Annotated
DecimalAnnotation = Annotated[decimal.Decimal, BeforeValidator(lambda v: v)]
class ExampleSchema(BaseModel):
example_value: DecimalAnnotation | None = Field(max_digits=10, decimal_places=4)
Environment
- Pydantic: 2
Why It Broke
The Pydantic library fails to apply 'max_digits' and 'decimal_places' constraints to Decimal fields when using annotations
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==1.10.19
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/10506
First fixed release: 1.10.19
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if the application relies on previous behavior of Pydantic 2.8.
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.19 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.