jax-ml/jax · error · TypeError

Cannot interpret value of type {typ} as an abstract array; i

Error message

Cannot interpret value of type {typ} as an abstract array; it does not have a dtype attribute

What it means

Raised by JAX's abstractification (get_aval) when a Python object has no registered abstract-value handler, no __jax_array__, and no dtype attribute, so JAX cannot interpret it as an array. It is the generic 'not a valid JAX type' failure at the abstract-value layer.

Source

Thrown at jax/_src/core.py:1995

  for t in typ.__mro__[1:]:
    if (aval_fn := pytype_aval_mappings.get(t)):
      return aval_fn(x)
  if isinstance(x, AbstractValue):
    return x
  if getattr(x, '__jax_array__', None) is not None:
    raise ValueError(
        'Triggering __jax_array__() during abstractification is no longer'
        ' supported. To avoid this error, either explicitly convert your object'
        ' using jax.numpy.array(), or register your object as a pytree.'
    )
  if hasattr(x, 'dtype'):
    aval = ShapedArray(
        np.shape(x),
        dtypes.canonicalize_dtype(x.dtype, allow_extended_dtype=True),
        weak_type=getattr(x, "weak_type", False),
    )
    return update_aval_with_sharding(aval, getattr(x, 'sharding', None))
  raise TypeError(
      f"Cannot interpret value of type {typ} as an abstract array; it "
      "does not have a dtype attribute")


# TODO(phawkins): the return type should be AbstractValue.
def typeof(x: Any) -> Any:
  """Return the JAX type (i.e. :class:`AbstractValue`) of the input.

  Raises a ``TypeError`` if ``x`` is not a valid JAX type.
  """
  typ = type(x)
  if (aval_fn := pytype_aval_mappings.get(typ)):  # fast path
    return aval_fn(x)
  for t in typ.__mro__[1:]:
    if (aval_fn := pytype_aval_mappings.get(t)):
      return aval_fn(x)
  if getattr(x, '__jax_array__', None) is not None:
    raise ValueError(

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Convert inputs to jnp.array/np.array before the call
  2. Register the object as a pytree if it is a container of arrays
  3. Mark non-array arguments as static (static_argnums/static_argnames) if they should be treated as constants
  4. Check for None/str values leaking into numerical code paths

Example fix

// before
jax.jit(fn)("hello", x)

// after
jax.jit(fn, static_argnums=0)("hello", x)
# or convert: jax.jit(fn)(jnp.array([1.0]), x)
Defensive patterns

Strategy: type-guard

Validate before calling

import numpy as np, jax.numpy as jnp
def is_arraylike(x):
    return isinstance(x, (int, float, bool, complex, np.ndarray)) or hasattr(x, 'dtype') or hasattr(x, '__jax_array__')
assert is_arraylike(x), f'cannot pass {type(x)} to jax'

Type guard

def is_arraylike(x) -> bool:
    return isinstance(x, (int, float, bool, complex, np.ndarray)) or hasattr(x, 'dtype') or hasattr(x, '__jax_array__')

Prevention

When it happens

Trigger: Passing arbitrary Python objects (strings, dicts, arbitrary class instances, None) where an array is expected inside jit/pmap/vmap/grad; passing unregistered custom objects without dtype.

Common situations: Forgetting to convert lists/strings; passing a dict of params without treating it as a pytree; feeding None as an optional argument; passing objects like datetime or paths into traced functions.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/fa1f1a710d325677. Report an issue: GitHub.