{"record":{"id":"82649dbbb43b4052","repo":"OpenBB-finance/OpenBB","slug":"unexpected-data-format-expected-dict-got-type","errorCode":null,"errorMessage":"Unexpected data format. Expected dict, got: {type(data).__name__}","messagePattern":"Unexpected data format\\. Expected dict, got: (.+?)","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/benzinga/openbb_benzinga/models/analyst_search.py","lineNumber":436,"sourceCode":"        from openbb_core.provider.utils.helpers import amake_request, get_querystring\n\n        token = credentials.get(\"benzinga_api_key\") if credentials else \"\"\n        querystring = get_querystring(query.model_dump(by_alias=True), [])\n        url = f\"https://api.benzinga.com/api/v2.1/calendar/ratings/analysts?{querystring}&token={token}\"\n        data = await amake_request(url, response_callback=response_callback, **kwargs)\n\n        if (isinstance(data, list) and not data) or (\n            isinstance(data, dict) and not data.get(\"analyst_ratings_analyst\")\n        ):\n            raise EmptyDataError(\"No ratings data returned.\")\n\n        if isinstance(data, dict) and \"analyst_ratings_analyst\" not in data:\n            raise OpenBBError(\n                f\"Unexpected data format. Expected 'analyst_ratings_analyst' key, got: {list(data.keys())}\"\n            )\n\n        if not isinstance(data, dict):\n            raise OpenBBError(\n                f\"Unexpected data format. Expected dict, got: {type(data).__name__}\"\n            )\n\n        return data[\"analyst_ratings_analyst\"]\n\n    @staticmethod\n    def transform_data(\n        query: BenzingaAnalystSearchQueryParams,\n        data: list[dict],\n        **kwargs: Any,\n    ) -> list[BenzingaAnalystSearchData]:\n        \"\"\"Transform the data.\"\"\"\n        results: list[BenzingaAnalystSearchData] = []\n        for item in data:\n            if item.get(\"firm_id\"):\n                result = {\n                    \"updated\": item.get(\"updated\", None),\n                    \"firm_id\": item.get(\"firm_id\", None),","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/benzinga/openbb_benzinga/models/analyst_search.py#L418-L454","documentation":"The final type check in analyst_search.py:436: after ruling out the expected dict shape, any non-dict payload (typically a list or a str HTML error page that response_callback decoded) raises OpenBBError(\"Unexpected data format. Expected dict, got: {type(data).__name__}\"). It fires only when the earlier emptiness and key checks passed shape-wise impossible paths — i.e. the callback returned a list that was non-empty, or a scalar.","triggerScenarios":"response_callback returning a parsed list (e.g. Benzinga serving a bare JSON array on some error paths), or a string, making `data` neither the guarded empty list nor a dict.","commonSituations":"Benothinga API revisions returning top-level arrays; proxies/interceptors returning HTML that decodes to str; mocked responses in tests that return lists.","solutions":["Inspect type(data) and the raw response (log it) to see the actual payload shape from your network path.","Upgrade openbb-benzinga — schema handling for this endpoint is maintained in the package's response_callback.","If you control the callback, normalize to dict before returning it.","Treat OpenBBError here as a provider-contract break: report it, don't retry blindly."],"exampleFix":"# before\nraise OpenBBError(f\"Unexpected data format. Expected dict, got: {type(data).__name__}\")\n\n# after\nif isinstance(data, list):\n    rows = data  # Benzinga occasionally returns a bare array\nelse:\n    rows = data[\"analyst_ratings_analyst\"]","handlingStrategy":"type-guard","validationCode":"assert isinstance(data, dict), f\"expected dict payload, got {type(data).__name__}\"\nassert \"analyst_ratings_analyst\" in data, f\"unexpected keys: {list(data.keys())}\"","typeGuard":"def is_analyst_payload(data) -> bool:\n    return isinstance(data, dict) and \"analyst_ratings_analyst\" in data","tryCatchPattern":"from openbb_core.app.model.abstract.error import OpenBBError\ntry:\n    rows = data[\"analyst_ratings_analyst\"]\nexcept (OpenBBError, TypeError):\n    logger.error(\"unexpected Benzinga payload type: %s\", type(data).__name__)","preventionTips":["In tests, mock amake_request to return {\"analyst_ratings_analyst\": [...]}.","Log raw payload types when integrating through proxies.","Update openbb-benzinga after Benzinga API changes."],"tags":["python","openbb","benzinga","provider","type-validation"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}