python data_error ai_generated true

pydantic.errors.ListError: list length must be at least 3

ID: python/pydantic-list-length-mismatch

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2024-01-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2.x active

Root Cause

A list field with Field(min_length=3) receives a list with fewer than 3 elements.

generic

中文

带有 Field(min_length=3) 的列表字段接收到少于 3 个元素的列表。

Workarounds

  1. 90% success
    Ensure list has enough elements: data = data + [default]*n
  2. 95% success
    Adjust Field constraint: Field(min_length=1)

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Validator must return value; otherwise ConfigError.

  2. 70% fail

    None may not be valid element type.