OpenBB-finance/OpenBB · error · ValueError
Label must be specified
Error message
Label must be specified
What it means
In OpenBBFigure.add_legend_label (openbb_figure.py:801), after the trace-lookup block the method requires a truthy `label` — the visible text of the dummy scatter it adds to build the legend entry. An empty/None label makes the legend entry invisible and meaningless, so it raises ValueError("Label must be specified").
Source
Thrown at openbb_platform/obbject_extensions/charting/openbb_charting/core/openbb_figure.py:801
If label is not specified and trace is not specified
"""
if trace:
for trace_ in self.data:
if trace_.name == trace: # type: ignore
for arg, default in zip(
[label, mode, marker, line_dash],
[trace, trace_.mode, trace_.marker, trace_.line_dash], # type: ignore
):
if not arg and default:
arg = default # noqa: PLW2901
kwargs.update(dict(yaxis=trace_.yaxis)) # type: ignore
break
else:
raise ValueError(f"Trace '{trace}' not found")
if not label:
raise ValueError("Label must be specified")
self.add_scatter(
x=[None],
y=[None],
mode=mode or "lines",
name=label,
marker=marker or dict(),
line_dash=line_dash or "solid",
legendrank=legendrank,
**kwargs,
)
def show( # noqa: PLR0915
self,
*args,
external: bool = False,
export_image: Path | str | None = "", # pylint: disable=W0613
**kwargs,View on GitHub (pinned to 3e071fcc2c)
Solutions
- Pass a non-empty label: fig.add_legend_label(label="200D MA").
- Default it from config: label = cfg.get("label") or "unnamed series".
- Skip the call entirely when no label is available — a legend entry without text serves no purpose.
Example fix
# before
fig.add_legend_label(trace="sma", label=cfg.get("text")) # None -> ValueError
# after
label = cfg.get("text") or cfg.get("label")
if label:
fig.add_legend_label(trace="sma", label=label) Defensive patterns
Strategy: validation
Validate before calling
label = label or cfg.get("text") or ""
if label:
fig.add_legend_label(trace=trace, label=label) Type guard
def valid_legend_label(label) -> bool:
return isinstance(label, str) and bool(label.strip()) Try / catch
try:
fig.add_legend_label(trace=trace, label=label)
except ValueError as e:
if "Label must be specified" in str(e):
pass # nothing to show
else:
raise Prevention
- Default label strings in config-driven loops: entry.get("label") or "unnamed".
- Skip the call when no text is available.
- Watch for parameter renames (text vs label) when copying examples.
When it happens
Trigger: Calling add_legend_label() with no arguments, or with label=""/None — including code that reads the label from a config key that is absent and defaults to None.
Common situations: Programmatic loops over indicator configs where some entries lack a label field; refactors that renamed the parameter (e.g. text->label) leaving the old call shape.
Related errors
- Trace '{trace}' not found
- Error adding trend line: {e}
- Unknown indicator: {indicator}
- {k} is not a valid indicator.
- pywry is not installed
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/ab98b5d78db3a0a8.
Report an issue: GitHub.