reflex-dev/reflex · error · ValueError

column field should be specified when the data field is a li

Error message

column field should be specified when the data field is a list type

What it means

data_table cannot infer column definitions from plain list data — the list's contents have no schema. When data is a list-typed value, columns must be provided explicitly.

Source

Thrown at packages/reflex-components-gridjs/src/reflex_components_gridjs/datatable.py:92

        ):
            msg = "Annotation of the computed var assigned to the column field should be provided."
            raise ValueError(msg)

        # If data is a pandas dataframe and columns are provided throw an error.
        if (
            types.is_dataframe(type(data))
            or (isinstance(data, Var) and types.is_dataframe(data._var_type))
        ) and columns is not None:
            msg = "Cannot pass in both a pandas dataframe and columns to the data_table component."
            raise ValueError(msg)

        # If data is a list and columns are not provided, throw an error
        if (
            (isinstance(data, Var) and types.typehint_issubclass(data._var_type, list))
            or isinstance(data, list)
        ) and columns is None:
            msg = "column field should be specified when the data field is a list type"
            raise ValueError(msg)

        # Create the component.
        return super().create(
            *children,
            **props,
        )

    def add_imports(self) -> ImportDict:
        """Add the imports for the datatable component.

        Returns:
            The import dict for the component.
        """
        return {"": "gridjs/dist/theme/mermaid.css"}

    def _render(self) -> Tag:
        if isinstance(self.data, Var) and types.is_dataframe(self.data._var_type):
            self.columns = self.data._replace(

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Pass columns=["col1", "col2"] (or column dicts) alongside list data
  2. Or pass a pandas DataFrame instead, which derives columns automatically
  3. For var data, annotate the state var as list[list[Any]] and still supply columns

Example fix

# before
rx.data_table(data=State.rows)
# after
rx.data_table(data=State.rows, columns=["id", "name"])
Defensive patterns

Strategy: validation

Validate before calling

if (isinstance(data, list) or _is_list_var(data)) and columns is None:
    columns = default_columns or ['col%d' % i for i in range(len(data[0]))]

Type guard

def is_list_data(data: Any) -> bool:
    return isinstance(data, list) or (hasattr(data, '_var_type') and getattr(data._var_type, '__origin__', None) in (list,))

Prevention

When it happens

Trigger: rx.data_table(data=[[1, "a"], [2, "b"]]) or data=State.rows (list-typed var) without columns=...

Common situations: Switching from a DataFrame to a list of rows (e.g. after serialization or a fetch) and dropping the columns argument.

Related errors


AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28). Data as JSON: /api/errors/9cfe88cb098c226b. Report an issue: GitHub.