reflex-dev/reflex · error · ValueError
Serialized dataframe should be a dict.
Error message
Serialized dataframe should be a dict.
What it means
Internally, data_table serializes a pandas DataFrame via serialize(), expecting a dict with 'data' and 'columns' keys. If a custom serializer or DataFrame format returns something else, this invariant error fires.
Source
Thrown at packages/reflex-components-gridjs/src/reflex_components_gridjs/datatable.py:123
"""
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(
_js_expr=f"{self.data._js_expr}.columns",
_var_type=list[Any],
)
self.data = self.data._replace(
_js_expr=f"{self.data._js_expr}.data",
_var_type=list[list[Any]],
)
if types.is_dataframe(type(self.data)):
# If given a pandas df break up the data and columns
data = serialize(self.data)
if not isinstance(data, dict):
msg = "Serialized dataframe should be a dict."
raise ValueError(msg)
self.columns = LiteralVar.create(data["columns"])
self.data = LiteralVar.create(data["data"])
# Render the table.
return super()._render()
View on GitHub (pinned to 45b8ed5ab7)
Solutions
- Pass a vanilla pandas DataFrame (convert subclasses via pd.DataFrame(df))
- Or pre-convert: pass data=df.to_dict('records') style list plus explicit columns
- Check for mismatched reflex package versions and uv sync
- Report upstream if a plain DataFrame triggers it
Example fix
# before rx.data_table(data=CustomDF subclass_instance) # after rx.data_table(data=pd.DataFrame(subclass_instance))
Defensive patterns
Strategy: try-catch
Validate before calling
from reflex.utils import serialize assert isinstance(serialize(pd.DataFrame(df)), dict), 'unexpected serializer output'
Try / catch
try:
comp = rx.data_table(data=df)
except ValueError as e:
if 'Serialized dataframe' in str(e):
comp = rx.data_table(data=df.to_dict('records'), columns=list(df.columns))
else:
raise Prevention
- Convert DataFrame subclasses to plain pd.DataFrame
- Keep reflex workspace packages version-synced (uv sync)
When it happens
Trigger: Passing a DataFrame whose serialize() output is not a dict — e.g. a custom pandas subclass or overridden serialization hook in the app.
Common situations: Rare; usually caused by using non-standard DataFrame wrappers or an incompatible reflex/radix serialization version.
Related errors
- The component `{child_name}` can only be a child of the comp
- Cannot serialize color that contains non-literal vars.
- Color is not a valid color.
- No valid JSON representation for {self}
- The keys and values of the object must be literal vars to ge
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/935c5e1e41d0ee1e.
Report an issue: GitHub.