OpenBB-finance/OpenBB · error · OpenBBError
Unexpected data format. Expected 'analyst_ratings_analyst' k
Error message
Unexpected data format. Expected 'analyst_ratings_analyst' key, got: {list(data.keys())} What it means
analyst_search.py:431 inspects the Benzinga ratings-analysts response shape: a dict that lacks the 'analyst_ratings_analyst' key entirely raises OpenBBError("Unexpected data format. Expected 'analyst_ratings_analyst' key, got: {list(data.keys())}"). It means the endpoint answered successfully but with a schema this fetcher cannot parse — e.g. an error body or an API revision.
Source
Thrown at openbb_platform/providers/benzinga/openbb_benzinga/models/analyst_search.py:431
**kwargs: Any,
) -> list[dict]:
"""Extract the raw data."""
# pylint: disable=import-outside-toplevel
from openbb_benzinga.utils.helpers import response_callback
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] = []View on GitHub (pinned to 3e071fcc2c)
Solutions
- Log list(data.keys()) (it's in the message) to see what Benzinga actually returned — an 'error'/'message' key points at auth or limits.
- Validate/refresh the benzinga credentials (obbject.user.credentials.benzinga_api_key) and re-test.
- Pin/upgrade openbb-benzinga to the release matching the current API schema.
- Handle OpenBBError separately from EmptyDataError so schema problems aren't silenced as no-data.
Example fix
# before
data = await amake_request(url, response_callback=response_callback)
# OpenBBError: Unexpected data format. Expected 'analyst_ratings_analyst' key, got: ['error']
# after
if isinstance(data, dict) and "error" in data:
raise OpenBBError(f"Benzinga API error: {data['error']}")
rows = data.get("analyst_ratings_analyst") or [] Defensive patterns
Strategy: try-catch
Validate before calling
# Pre-check key health with any cheap Benzinga call
status = await amake_request("https://api.benzinga.com/api/v2.1/calendar/ratings?limit=1&token=" + token, response_callback=response_callback)
if isinstance(status, dict) and ("error" in status or "ratings" not in status):
raise RuntimeError(f"Benzinga auth/schema problem: {list(status.keys())}") Type guard
def is_expected_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 = await fetcher.a_fetch_data(query, credentials)
except OpenBBError as e:
if "Unexpected data format" in str(e):
logger.error("Benzinga schema/auth issue: %s", e) # inspect keys, fix creds or version
raise
raise Prevention
- Keep the benzinga_api_key credential current and quota-monitored.
- Separate OpenBBError (schema/auth) from EmptyDataError (no rows) in error handling.
- Upgrade openbb-benzinga when Benzinga revises response shapes.
When it happens
Trigger: Benzinga returns {"error": "..."} or an auth/limit message dict, or changes/adds wrapper keys, so 'analyst_ratings_analyst' is absent while the payload is still valid JSON dict.
Common situations: Expired or invalid API key producing a JSON error body, endpoint version bumps (v2.1 schema change), rate-limit responses that decode as dicts.
Related errors
- Unexpected data format. Expected 'ratings' key, got: {list(d
- No ratings data returned.
- Unexpected data format. Expected dict, got: {type(data).__na
- The request was returned empty.
- Unexpected data format. Expected dict, got: {type(data)}
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/6b4a05682b30e9f2.
Report an issue: GitHub.