OpenBB-finance/OpenBB · error · RuntimeError

Column '{data_col}' was not found in the original data. Exte

Error message

Column '{data_col}' was not found in the original data. External data injection is not supported unless `allow_unsafe = True`.

What it means

The FRED charting view allows injecting an external DataFrame via kwargs['data'], but only as a safety hatch: by default (allow_unsafe=False) every column of the injected data must also exist in the original FRED results. If any injected column is not among the original response columns, this RuntimeError fires to prevent unverified external series from being plotted as if they were FRED data.

Source

Thrown at openbb_platform/extensions/economy/openbb_economy/economy_views.py:72

        allow_unsafe = kwargs.get("allow_unsafe", False)
        dropnan = kwargs.get("dropna", True)
        normalize = kwargs.get("normalize", False)

        data_cols = []
        data = kwargs.get("data")

        if isinstance(data, DataFrame) and not data.empty:
            data_cols = data.columns.to_list()
            df_ta = data

        else:
            df_ta = basemodel_to_df(kwargs["obbject_item"], index="date")  # type: ignore

        # Check for unsupported external data injection.
        if allow_unsafe is False and data_cols:
            for data_col in data_cols:
                if data_col not in columns:
                    raise RuntimeError(
                        f"Column '{data_col}' was not found in the original data."
                        + " External data injection is not supported unless `allow_unsafe = True`."
                    )

        # Align the data so each column has the same index and length.
        if dropnan:
            df_ta = df_ta.dropna(how="any")

        if df_ta.empty or len(df_ta) < 2:
            raise ValueError(
                "No data is left after dropping NaN values. Try setting `dropnan = False`,"
                + " or use the `frequency` parameter on request."
            )

        columns = df_ta.columns.to_list()

        metadata = kwargs["extra"].get("results_metadata", {})  # type: ignore

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Ensure injected columns match names already present in the FRED response (e.g. reuse the series id as column name).
  2. Opt in explicitly: pass allow_unsafe=True when you intentionally inject foreign columns.
  3. Better: plot external series with the generic charting (obb.charting.line_chart / figure API) instead of the FRED-specific view.

Example fix

# before
res = obb.economy.fred.series('GDP', provider='fred').charting.fred(data=df_with_extra_col)

# after
# option 1: only existing columns
df = df[['GDP']]
# option 2: explicit opt-in
res = obb.economy.fred.series('GDP', provider='fred').charting.fred(data=df_with_extra_col, allow_unsafe=True)
Defensive patterns

Strategy: validation

Validate before calling

original_cols = set(res.to_df().columns)
injected_cols = set(df.columns)
extra = injected_cols - original_cols
if extra and not allow_unsafe:
    df = df[list(injected_cols - extra)]  # drop foreign columns

Type guard

def columns_are_subset(df, allowed: set[str]) -> bool:
    """True when every injected column exists in the original response."""
    return set(df.columns).issubset(allowed)

Try / catch

try:
    fig = res.charting.fred(data=df)
except RuntimeError as e:
    if 'External data injection' in str(e):
        # rename to existing columns or consciously pass allow_unsafe=True
        ...

Prevention

When it happens

Trigger: Calling the FRED chart method with data=some_df whose columns are not a subset of the FRED response fields, without setting allow_unsafe=True.

Common situations: Trying to overlay a locally computed series (e.g. a rolling average with a new column name) on FRED data, or passing a renamed/reindexed DataFrame produced by an upstream transformation.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/43208b170fbd821c. Report an issue: GitHub.