Jump to solution
Verify

The Fix

pip install pydantic==1.10.3

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

Production note: This usually shows up under retries/timeouts. Treat it as a side-effect risk until you can verify behavior with a canary + real traffic.

Jump to Verify Open PR/Commit
@@ -0,0 +1 @@ @@ -0,0 +1 @@ +Allow dict schemas to have both `patternProperties` and `additionalProperties` diff --git a/pydantic/schema.py b/pydantic/schema.py index e7af56f120d..1348fbd5eef 100644
repro.py
from pydantic.v1 import ConstrainedStr, Model class LengthKey(ConstrainedStr): regex = ".{0,64}" class LengthValue(ConstrainedStr): max_length = 64 class TestModel(BaseModel): mapping: dict[LengthKey, LengthValue] print(TestModel.schema()) {'title': 'TestModel', 'type': 'object', 'properties': {'mapping': {'title': 'Mapping', 'type': 'object', 'patternProperties': {'.{0,64}': {'type': 'string', 'maxLength': 64}}, 'additionalProperties': {'type': 'string', 'maxLength': 64}}}, 'required': ['mapping']}
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.3\nWhen NOT to use: This fix should not be applied if using a version of Pydantic that does not support the new schema behavior.\n\n

Why This Fix Works in Production

  • Trigger: print(TestModel.schema())
  • Mechanism: The logic made patternProperties and additionalProperties mutually exclusive in dict schemas
  • Why the fix works: Allows dict schemas to have both `patternProperties` and `additionalProperties`, resolving the issue with mutually exclusive properties in JSON Schema. (first fixed release: 1.10.3).
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 logic made patternProperties and additionalProperties mutually exclusive in dict schemas
  • Production symptom (often without a traceback): print(TestModel.schema())

Proof / Evidence

Discussion

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

“This is working as expected on V2: PRs welcomed to fix this in v1, but closing for now (see our policy).”
@Viicos · 2025-02-06 · confirmation · source
“@Viicos seems like this was broken in https://github.com/pydantic/pydantic/pull/4641”
@ElectronicRU · 2025-02-06 · source

Failure Signature (Search String)

  • print(TestModel.schema())
  • - [ ] [Compatibility between releases](https://docs.pydantic.dev/changelog/)
Copy-friendly signature
signature.txt
Failure Signature ----------------- print(TestModel.schema()) - [ ] [Compatibility between releases](https://docs.pydantic.dev/changelog/)

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- print(TestModel.schema()) - [ ] [Compatibility between releases](https://docs.pydantic.dev/changelog/)

Minimal Reproduction

repro.py
from pydantic.v1 import ConstrainedStr, Model class LengthKey(ConstrainedStr): regex = ".{0,64}" class LengthValue(ConstrainedStr): max_length = 64 class TestModel(BaseModel): mapping: dict[LengthKey, LengthValue] print(TestModel.schema()) {'title': 'TestModel', 'type': 'object', 'properties': {'mapping': {'title': 'Mapping', 'type': 'object', 'patternProperties': {'.{0,64}': {'type': 'string', 'maxLength': 64}}, 'additionalProperties': {'type': 'string', 'maxLength': 64}}}, 'required': ['mapping']}

Environment

  • Python: 3.12

What Broke

JSON Schema generation fails to accurately represent dict schemas with regex keys.

Why It Broke

The logic made patternProperties and additionalProperties mutually exclusive in dict schemas

Fix Options (Details)

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

pip install pydantic==1.10.3

When NOT to use: This fix should not be applied if using a version of Pydantic that does not support the new schema behavior.

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

Option D — Guard side-effects with OnceOnly Guardrail for side-effects

Mitigate duplicate external side-effects under retries/timeouts/agent loops by gating the operation before calling external systems.

  • Place OnceOnly between your code/agent and real side-effects (Stripe, emails, CRM, APIs).
  • Use a stable key per side-effect (e.g., customer_id + action + idempotency_key).
  • Fail-safe: configure fail-open vs fail-closed based on blast radius and spend risk.
Show example snippet (optional)
onceonly.py
from onceonly import OnceOnly import os once = OnceOnly(api_key=os.environ["ONCEONLY_API_KEY"], fail_open=True) # Stable idempotency key per real side-effect. # Use a request id / job id / webhook delivery id / Stripe event id, etc. event_id = "evt_..." # replace key = f"stripe:webhook:{event_id}" res = once.check_lock(key=key, ttl=3600) if res.duplicate: return {"status": "already_processed"} # Safe to execute the side-effect exactly once. handle_event(event_id)

See OnceOnly SDK

When NOT to use: Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.

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

First fixed release: 1.10.3

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 should not be applied if using a version of Pydantic that does not support the new schema behavior.
  • Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.

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

Related Issues

No related fixes found.

Sources

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