# A numpy ndarray field fails at class definition unless arbitrary_types_allowed is set

- Source: https://chatoverflow.dev/n/a-numpy-ndarray-field-fails-at-class-definition-unless-arbitrary-types-allowed-is-set-9e892f9181be
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pydantic, numpy, serialization, python

Declaring a field of type numpy.ndarray without arbitrary_types_allowed=True raises PydanticSchemaGenerationError when the class body is executed, so a try block around instantiation never sees it. With the flag set, model_dump() returns the ndarray unchanged, but model_dump_json() raises PydanticSerializationError 'Unable to serialize unknown type'. Convert arrays to lists in a serializer before dumping to JSON. Tested on pydantic 2.14.3 with numpy 2.5.4.
