keras-team/keras · error · TypeError

Unexpected keyword arguments

Error message

Unexpected keyword arguments: {', '.join(kwargs.keys())}

What it means

Guard in KerasTensor.__init__: after the two recognized legacy kwargs (ragged_rank, row_splits_dtype) are popped, extra keyword arguments remain. KerasTensor's constructor accepts no other kwargs, so this is a generic sentinel flagging unrecognized/misspelled keyword names.

Solutions

  1. Remove the unsupported keyword arguments; KerasTensor only accepts shape, dtype, sparse, ragged, record_history, name, ragged_rank, row_splits_dtype.
  2. Check for typos (e.g. 'batch_shape' or 'trainable' left over from old tf.keras code).
  3. Pass shape/dtype positionally where porting legacy tf.KerasTensor code.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/common/keras_tensor.py:45 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/b089f049a9989b70. Report an issue: GitHub.

Appendix: source

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

    dtype is called "static shape inference".
    """

    def __init__(
        self,
        shape,
        dtype="float32",
        sparse=False,
        ragged=False,
        record_history=True,
        name=None,
        **kwargs,
    ):
        from keras.src import backend

        ragged_rank = kwargs.pop("ragged_rank", None)
        row_splits_dtype = kwargs.pop("row_splits_dtype", None)
        if kwargs:
            raise TypeError(
                f"Unexpected keyword arguments: {', '.join(kwargs.keys())}"
            )

        self._shape = backend.standardize_shape(shape)
        self._dtype = backend.standardize_dtype(dtype)
        self._sparse = bool(sparse)
        self._ragged = bool(ragged)
        if self._sparse and self._ragged:
            raise ValueError(
                "KerasTensor cannot have `sparse=True` and `ragged=True` at "
                "the same time."
            )
        self._ragged_rank = (
            int(ragged_rank) if ragged_rank is not None else None
        )
        self._row_splits_dtype = (
            backend.standardize_dtype(row_splits_dtype)
            if row_splits_dtype is not None

View on GitHub (pinned to 7a34a03db6)