{"record":{"id":"43208b170fbd821c","repo":"OpenBB-finance/OpenBB","slug":"column-data-col-was-not-found-in-the-original","errorCode":null,"errorMessage":"Column '{data_col}' was not found in the original data. External data injection is not supported unless `allow_unsafe = True`.","messagePattern":"Column '(.+?)' was not found in the original data\\. External data injection is not supported unless `allow_unsafe = True`\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/economy/openbb_economy/economy_views.py","lineNumber":72,"sourceCode":"        allow_unsafe = kwargs.get(\"allow_unsafe\", False)\n        dropnan = kwargs.get(\"dropna\", True)\n        normalize = kwargs.get(\"normalize\", False)\n\n        data_cols = []\n        data = kwargs.get(\"data\")\n\n        if isinstance(data, DataFrame) and not data.empty:\n            data_cols = data.columns.to_list()\n            df_ta = data\n\n        else:\n            df_ta = basemodel_to_df(kwargs[\"obbject_item\"], index=\"date\")  # type: ignore\n\n        # Check for unsupported external data injection.\n        if allow_unsafe is False and data_cols:\n            for data_col in data_cols:\n                if data_col not in columns:\n                    raise RuntimeError(\n                        f\"Column '{data_col}' was not found in the original data.\"\n                        + \" External data injection is not supported unless `allow_unsafe = True`.\"\n                    )\n\n        # Align the data so each column has the same index and length.\n        if dropnan:\n            df_ta = df_ta.dropna(how=\"any\")\n\n        if df_ta.empty or len(df_ta) < 2:\n            raise ValueError(\n                \"No data is left after dropping NaN values. Try setting `dropnan = False`,\"\n                + \" or use the `frequency` parameter on request.\"\n            )\n\n        columns = df_ta.columns.to_list()\n\n        metadata = kwargs[\"extra\"].get(\"results_metadata\", {})  # type: ignore\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/economy/openbb_economy/economy_views.py#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure injected columns match names already present in the FRED response (e.g. reuse the series id as column name).","Opt in explicitly: pass allow_unsafe=True when you intentionally inject foreign columns.","Better: plot external series with the generic charting (obb.charting.line_chart / figure API) instead of the FRED-specific view."],"exampleFix":"# before\nres = obb.economy.fred.series('GDP', provider='fred').charting.fred(data=df_with_extra_col)\n\n# after\n# option 1: only existing columns\ndf = df[['GDP']]\n# option 2: explicit opt-in\nres = obb.economy.fred.series('GDP', provider='fred').charting.fred(data=df_with_extra_col, allow_unsafe=True)","handlingStrategy":"validation","validationCode":"original_cols = set(res.to_df().columns)\ninjected_cols = set(df.columns)\nextra = injected_cols - original_cols\nif extra and not allow_unsafe:\n    df = df[list(injected_cols - extra)]  # drop foreign columns","typeGuard":"def columns_are_subset(df, allowed: set[str]) -> bool:\n    \"\"\"True when every injected column exists in the original response.\"\"\"\n    return set(df.columns).issubset(allowed)","tryCatchPattern":"try:\n    fig = res.charting.fred(data=df)\nexcept RuntimeError as e:\n    if 'External data injection' in str(e):\n        # rename to existing columns or consciously pass allow_unsafe=True\n        ...","preventionTips":["Name injected columns exactly as the FRED series ids in the response.","Only set allow_unsafe=True deliberately, never by default in shared code.","Use generic charting for genuinely external series."],"tags":["charting","fred","data-injection","safety-guard"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}