keras-team/keras · error · ValueError

Argument `name` must be a string and cannot contain…

Error message

Argument `name` must be a string and cannot contain character `/`. Received: name={name}

What it means

Raised in Variable.__init__ when the user-supplied name is not a string or contains '/'. Variable names become path segments in the global variable namespace where '/' separates scopes, so a slash inside one name would break path resolution; the check guards the name argument before creation.

Solutions

  1. Pass a name string without '/' (use '-' or '_' instead)
  2. Omit name to let Keras auto-generate a safe name
  3. If hierarchical naming is wanted, use name_scope rather than embedding slashes in the name
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/common/variables.py:109 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/d42de0bccd21ef06. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/common/variables.py:109

    ```
    """

    def __init__(
        self,
        initializer,
        shape=None,
        dtype=None,
        trainable=True,
        autocast=True,
        aggregation="none",
        synchronization="auto",
        name=None,
        layout=None,
        **kwargs,
    ):
        name = name or auto_name(self.__class__.__name__)
        if not isinstance(name, str) or "/" in name:
            raise ValueError(
                "Argument `name` must be a string and "
                "cannot contain character `/`. "
                f"Received: name={name}"
            )
        if aggregation not in (
            None,
            "none",
            "mean",
            "sum",
            "only_first_replica",
        ):
            raise ValueError(
                "Invalid value for argument `aggregation`. Expected "
                "one of `None`, `'none'`, `'mean'`, `'sum'`, "
                "`'only_first_replica'`. "
                f"Received: aggregation={aggregation}"
            )
        if aggregation is None:

View on GitHub (pinned to 7a34a03db6)