pydantic/pydantic · error · TypeError
Fields of type "{origin}" are not supported.
Error message
Fields of type "{origin}" are not supported. What it means
Raised by ModelField._type_analysis as the final else branch when the field's type origin is a generic class that pydantic v1 does not recognize and arbitrary_types_allowed is False. Recognized origins include standard containers (list/tuple/set/dict/Iterable/Mapping/Deque/Counter/Type) and types exposing __get_validators__; anything else falls through to this error.
Source
Thrown at pydantic/v1/fields.py:753
self.type_ = get_args(self.type_)[1]
self.shape = SHAPE_MAPPING
# Equality check as almost everything inherits form Iterable, including str
# check for Iterable and CollectionsIterable, as it could receive one even when declared with the other
elif origin in {Iterable, CollectionsIterable}:
self.type_ = get_args(self.type_)[0]
self.shape = SHAPE_ITERABLE
self.sub_fields = [self._create_sub_type(self.type_, f'{self.name}_type')]
elif issubclass(origin, Type): # type: ignore
return
elif hasattr(origin, '__get_validators__') or self.model_config.arbitrary_types_allowed:
# Is a Pydantic-compatible generic that handles itself
# or we have arbitrary_types_allowed = True
self.shape = SHAPE_GENERIC
self.sub_fields = [self._create_sub_type(t, f'{self.name}_{i}') for i, t in enumerate(get_args(self.type_))]
self.type_ = origin
return
else:
raise TypeError(f'Fields of type "{origin}" are not supported.')
# type_ has been refined eg. as the type of a List and sub_fields needs to be populated
self.sub_fields = [self._create_sub_type(self.type_, '_' + self.name)]
def prepare_discriminated_union_sub_fields(self) -> None:
"""
Prepare the mapping <discriminator key> -> <ModelField> and update `sub_fields`
Note that this process can be aborted if a `ForwardRef` is encountered
"""
assert self.discriminator_key is not None
if self.type_.__class__ is DeferredType:
return
assert self.sub_fields is not None
sub_fields_mapping: Dict[str, 'ModelField'] = {}
all_aliases: Set[str] = set()
View on GitHub (pinned to 2e5f0e2b42)
Solutions
- Set arbitrary_types_allowed = True in the model Config so pydantic accepts the type without validation coercion.
- Add a classmethod __get_validators__ to the custom type so pydantic can validate it.
- Replace the unsupported type with a supported primitive or a pydantic-compatible wrapper.
Example fix
// before
class M(BaseModel):
df: pandas.DataFrame # raises: Fields of type "pandas.DataFrame" are not supported
# after
class M(BaseModel):
class Config:
arbitrary_types_allowed = True
df: pandas.DataFrame Defensive patterns
Strategy: validation
Validate before calling
def _ensure_type_supported(origin, arbitrary_allowed):
supported = (list, tuple, set, frozenset, dict, type, ...)
if origin is not None and origin not in supported and not hasattr(origin, '__get_validators__'):
if not arbitrary_allowed:
raise TypeError(f'enable arbitrary_types_allowed or add __get_validators__ to {origin}') Type guard
def type_is_supported_by_pydantic_v1(origin, arbitrary_allowed: bool) -> bool:
if origin is None:
return True
if hasattr(origin, '__get_validators__'):
return True
return bool(arbitrary_allowed) Prevention
- Set arbitrary_types_allowed = True when using third-party generic types.
- Implement __get_validators__ on custom types for full pydantic integration.
- Prefer native containers or pydantic-compatible types where possible.
When it happens
Trigger: Using a third-party or custom generic class as a field type that has no __get_validators__ method, without enabling arbitrary_types_allowed. Example: x: PathLibPath or x: SomeExternalGeneric[T] where the class is not a pydantic-compatible validator provider.
Common situations: Adding a pandas/numpy/attrs-typed field to a model; using a generic from a library that pydantic v1 has no built-in support for; upgrading pydantic where v2-only types are used against the v1 compatibility shim.
Related errors
- cannot specify both default and default_factory
- cannot specify multiple `Annotated` `Field`s for {field_name
- `Field` default cannot be set in `Annotated` for {field_name
- cannot specify `Annotated` and value `Field`s together for {
- `discriminator` can only be used with `Union` type with more
AI-assisted analysis of pydantic/pydantic@2e5f0e2b42 (2026-08-04).
Data as JSON: /data/errors/7168967341b90346.json.
Report an issue: GitHub.