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%.
@@ -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')
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()
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==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).
- 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
- GitHub issue: #9256
- Fix PR: https://github.com/pydantic/pydantic/pull/9303
- First fixed release: 2.7.2
- 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.62
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!”
“Ok I don't think this is actually a 2.7 issue (can reproduce in 2.6.4).”
“Removing this from the 2.7 milestone, great first issue if someone wants to pick this up!”
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
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 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
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
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.
When NOT to Use This Fix
- Do not apply this fix if the JSON schema needs to maintain `minLength` for other types.
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 |
|---|---|
| 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.