OpenBB-finance/OpenBB · error · ValueError
Content cannot be empty.
Error message
Content cannot be empty.
What it means
ValueError from the OmniWidgetResponseModel validator: the 'content' field is None. Note this is a strict None check, not a truthiness check — an empty string or empty dict passes this guard (and may fail later parsing instead), while a missing/None content fails here.
Source
Thrown at openbb_platform/extensions/platform_api/openbb_platform_api/response_models.py:214
data_format: dict | None = Field(
default=None,
description="Leave this field empty. This is populated by the model_validator.",
json_schema_extra={"x-widget_config": {"exclude": True}},
)
@model_validator(mode="after")
@classmethod
def validate_model(cls, values) -> "OmniWidgetResponseModel":
"""Validate the Omni widget content."""
# pylint: disable=import-outside-toplevel
import json # noqa
import re
import pandas as pd
content = getattr(values, "content", None)
if content is None:
raise ValueError("Content cannot be empty.")
parse_as = getattr(values, "parse_as", None)
if parse_as and parse_as not in ("table", "chart", "text"):
raise ValueError(
"Invalid parse_as value. Must be one of 'table', 'chart', or 'text'."
)
# If parameter was supplied, assume the data is formatted correctly.
if content and parse_as:
data_format = {
"data_type": "object",
"parse_as": parse_as,
}
values.data_format = data_format
del values.parse_as
return valuesView on GitHub (pinned to 3e071fcc2c)
Solutions
- Supply actual content: a DataFrame, dict, list, or string with the widget data
- Guard upstream: skip model construction or return an empty-widget placeholder when the fetch yields None
- Check for key-name mismatches between the producer dict and the model field ('data'/'payload' vs 'content')
Example fix
# before
OmniWidgetResponseModel(chart=True, content=df if fetched else None)
# after
if df is None:
df = pd.DataFrame()
OmniWidgetResponseModel(chart=True, content=df) Defensive patterns
Strategy: validation
Validate before calling
if content is None:
raise ValueError("upstream fetch returned no content; refusing to build widget")
# or substitute an explicit empty payload:
content = content if content is not None else pd.DataFrame()
model = OmniWidgetResponseModel(content=content, chart=chart) Type guard
def content_is_present(content: object) -> bool:
return content is not None Try / catch
try:
model = OmniWidgetResponseModel(content=content, chart=True)
except ValueError as e:
if "Content cannot be empty" in str(e):
model = OmniWidgetResponseModel(content=pd.DataFrame(), chart=True)
else:
raise Prevention
- Guard upstream fetchers: None means skip or substitute, never pass through
- Verify the producer dict uses the key 'content' (not 'data'/'payload')
- Remember only None fails here — empty strings/objects pass but may break later parsing
When it happens
Trigger: Constructing OmniWidgetResponseModel(content=None) or omitting content entirely when building the model from a dict that lacks the key (getattr default is None). Upstream data fetchers returning None on failure and that value flowing straight into the model.
Common situations: API endpoints whose data source returned nothing and the handler still builds the response model, dict keys named differently ('data' vs 'content'), refactors that renamed the field while callers still send the old key, JSON deserialization where content was explicitly null.
Related errors
- Invalid parse_as value. Must be one of 'table', 'chart', or
- Either 'content' or 'url' must be provided.
- Invalid URL reference provided
- At least one extension type must be selected.
- Incorrect email or password
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/50dda7aa9efdfc27.
Report an issue: GitHub.