keras-team/keras · error · ValueError

A KerasTensor is symbolic: it's a placeholder for a shape…

Error message

A KerasTensor is symbolic: it's a placeholder for a shape an a dtype. It doesn't have any actual numerical value. You cannot convert it to a NumPy array.

What it means

Raised from KerasTensor.__array__ when NumPy tries to materialize a KerasTensor as an array (np.array(x), x.numpy()-style calls, NumPy APIs taking it as input). Since the tensor is a symbolic placeholder without values, array conversion is impossible and this protocol method makes the failure explicit rather than silently producing garbage.

Solutions

  1. Call the model/function on actual data and convert the returned backend tensor with np.array
  2. Use the concrete input or output values instead of the symbolic KerasTensor
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/common/keras_tensor.py:164 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/433fada3dcd871f9. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/common/keras_tensor.py:164

        return ops.Squeeze(axis)(self)

    def __int__(self):
        raise ValueError(
            "A KerasTensor is symbolic: it's a placeholder for a shape "
            "an a dtype. It doesn't have any actual numerical value. "
            "You cannot convert it to an int."
        )

    def __float__(self):
        raise ValueError(
            "A KerasTensor is symbolic: it's a placeholder for a shape "
            "an a dtype. It doesn't have any actual numerical value. "
            "You cannot convert it to a float."
        )

    def __array__(self):
        raise ValueError(
            "A KerasTensor is symbolic: it's a placeholder for a shape "
            "an a dtype. It doesn't have any actual numerical value. "
            "You cannot convert it to a NumPy array."
        )

    def __jax_array__(self):
        raise ValueError(
            "A KerasTensor cannot be used as input to a JAX function. "
            "A KerasTensor is a symbolic placeholder for a shape and dtype, "
            "used when constructing Keras Functional models "
            "or Keras Functions. You can only use it as input to a Keras layer "
            "or a Keras operation (from the namespaces `keras.layers` "
            "and `keras.ops`). "
            "You are likely doing something like:\n\n"
            "```\n"
            "x = Input(...)\n"
            "...\n"
            "jax_fn(x)  # Invalid.\n"

View on GitHub (pinned to 7a34a03db6)