OpenBB-finance/OpenBB · error · OpenBBError
Unexpected data format. Expected dict, got: {type(data).__na
Error message
Unexpected data format. Expected dict, got: {type(data).__name__} What it means
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.
Source
Thrown at openbb_platform/providers/benzinga/openbb_benzinga/models/analyst_search.py:436
from openbb_core.provider.utils.helpers import amake_request, get_querystring
token = credentials.get("benzinga_api_key") if credentials else ""
querystring = get_querystring(query.model_dump(by_alias=True), [])
url = f"https://api.benzinga.com/api/v2.1/calendar/ratings/analysts?{querystring}&token={token}"
data = await amake_request(url, response_callback=response_callback, **kwargs)
if (isinstance(data, list) and not data) or (
isinstance(data, dict) and not data.get("analyst_ratings_analyst")
):
raise EmptyDataError("No ratings data returned.")
if isinstance(data, dict) and "analyst_ratings_analyst" not in data:
raise OpenBBError(
f"Unexpected data format. Expected 'analyst_ratings_analyst' key, got: {list(data.keys())}"
)
if not isinstance(data, dict):
raise OpenBBError(
f"Unexpected data format. Expected dict, got: {type(data).__name__}"
)
return data["analyst_ratings_analyst"]
@staticmethod
def transform_data(
query: BenzingaAnalystSearchQueryParams,
data: list[dict],
**kwargs: Any,
) -> list[BenzingaAnalystSearchData]:
"""Transform the data."""
results: list[BenzingaAnalystSearchData] = []
for item in data:
if item.get("firm_id"):
result = {
"updated": item.get("updated", None),
"firm_id": item.get("firm_id", None),View on GitHub (pinned to 3e071fcc2c)
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.
Example fix
# before
raise OpenBBError(f"Unexpected data format. Expected dict, got: {type(data).__name__}")
# after
if isinstance(data, list):
rows = data # Benzinga occasionally returns a bare array
else:
rows = data["analyst_ratings_analyst"] Defensive patterns
Strategy: type-guard
Validate before calling
assert isinstance(data, dict), f"expected dict payload, got {type(data).__name__}"
assert "analyst_ratings_analyst" in data, f"unexpected keys: {list(data.keys())}" Type guard
def is_analyst_payload(data) -> bool:
return isinstance(data, dict) and "analyst_ratings_analyst" in data Try / catch
from openbb_core.app.model.abstract.error import OpenBBError
try:
rows = data["analyst_ratings_analyst"]
except (OpenBBError, TypeError):
logger.error("unexpected Benzinga payload type: %s", type(data).__name__) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Benothinga API revisions returning top-level arrays; proxies/interceptors returning HTML that decodes to str; mocked responses in tests that return lists.
Related errors
- Unexpected data format. Expected dict, got: {type(data)}
- No ratings data returned.
- Unexpected data format. Expected 'analyst_ratings_analyst' k
- The request was returned empty.
- Unexpected data format. Expected 'ratings' key, got: {list(d
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/82649dbbb43b4052.
Report an issue: GitHub.