Jump to solution
Verify

The Fix

pip install pydantic==2.7.2

Based on closed pydantic/pydantic issue #9256 · 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
@@ -1442,6 +1442,7 @@ def _sequence_schema(self, sequence_type: Any) -> core_schema.CoreSchema: item_type_schema = self.generate_schema(item_type) list_schema = core_schema.list_schema(item_type_schema) + metadata = build_metadata_dict(initial_metadata={'known_metadata_as': typing.Sequence}) python_schema = core_schema.is_instance_schema(typing.Sequence, cls_repr='Sequence')
repro.py
from pydantic import BaseModel from typing import Sequence class Example(BaseModel): array: Sequence[int] = Field(default_factory=list, min_length=1) Example.model_json_schema()
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.7.2\nWhen NOT to use: Do not apply this fix if the JSON schema needs to maintain `minLength` for other types.\n\n

Why This Fix Works in Production

  • Trigger: When using min_length on Sequence field, outputted JSON schema is `minLength` instead of `minItems` for array type
  • Mechanism: The JSON schema for Sequence type incorrectly uses `minLength` instead of `minItems`
  • Why the fix works: Fixes the outputted JSON Schema for Sequence type to use `minItems` instead of `minLength`. (first fixed release: 2.7.2).
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 JSON schema for Sequence type incorrectly uses `minLength` instead of `minItems`
  • Production symptom (often without a traceback): When using min_length on Sequence field, outputted JSON schema is `minLength` instead of `minItems` for array type

Proof / Evidence

Discussion

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

“@skylander86, Thanks for reporting this! We can fix in a 2.7 patch release soon. Adding to the corresponding milestone!”
@sydney-runkle · 2024-04-16 · source
“Ok I don't think this is actually a 2.7 issue (can reproduce in 2.6.4).”
@sydney-runkle · 2024-04-18 · source
“Removing this from the 2.7 milestone, great first issue if someone wants to pick this up!”
@sydney-runkle · 2024-04-18 · source

Failure Signature (Search String)

  • When using min_length on Sequence field, outputted JSON schema is `minLength` instead of `minItems` for array type
  • Example.model_json_schema()
Copy-friendly signature
signature.txt
Failure Signature ----------------- When using min_length on Sequence field, outputted JSON schema is `minLength` instead of `minItems` for array type Example.model_json_schema()

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- When using min_length on Sequence field, outputted JSON schema is `minLength` instead of `minItems` for array type Example.model_json_schema()

Minimal Reproduction

repro.py
from pydantic import BaseModel from typing import Sequence class Example(BaseModel): array: Sequence[int] = Field(default_factory=list, min_length=1) Example.model_json_schema()

Environment

  • Python: 3.12
  • Pydantic: 2

What Broke

The outputted JSON schema does not enforce the minimum number of items in an array, leading to potential validation issues.

Why It Broke

The JSON schema for Sequence type incorrectly uses `minLength` instead of `minItems`

Fix Options (Details)

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

pip install pydantic==2.7.2

When NOT to use: Do not apply this fix if the JSON schema needs to maintain `minLength` for other types.

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

First fixed release: 2.7.2

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 apply this fix if the JSON schema needs to maintain `minLength` for other types.

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

Related Issues

No related fixes found.

Sources

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