python data_error ai_generated true

pydantic.errors.EnumError: value is not a valid enumeration member

ID: python/pydantic-enum-value-invalid

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-02-14First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2.x active

Root Cause

A field typed as an Enum receives a value not defined in the enumeration.

generic

中文

类型为枚举的字段接收到未在枚举中定义的值。

Workarounds

  1. 95% success
    Use enum member: Color.RED
  2. 90% success
    Add custom validator to map strings to enum

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Enum member type mismatch.

  2. 70% fail

    Pydantic expects the value, not name.