{"record":{"id":"540c31814c104145","repo":"OpenBB-finance/OpenBB","slug":"unexpected-response-format-expected-a-dictionary","errorCode":null,"errorMessage":"Unexpected response format. Expected a dictionary, got {type(response)}","messagePattern":"Unexpected response format\\. Expected a dictionary, got (.+?)","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/fred/openbb_fred/models/search.py","lineNumber":249,"sourceCode":"            [\"search_text\", \"limit\"] if query.release_id is not None else [\"limit\"]\n        )\n\n        if query.release_id is not None and query.order_by == \"search_rank\":\n            query.order_by = None  # type: ignore\n\n        querystring = get_querystring(query.model_dump(), exclude).replace(\" \", \"%20\")\n        url = url + querystring + f\"&file_type=json&api_key={api_key}\"\n        response = await fred_get(url)\n\n        if isinstance(response, dict) and \"error_code\" in response:\n            raise OpenBBError(\n                f\"FRED API Error -> Status Code: {response['error_code']} -> {response.get('error_message', '')}\"\n            )\n\n        if isinstance(response, dict) and \"count\" in response:\n            results = response.get(\"seriess\", [])\n            return results\n        raise OpenBBError(\n            f\"Unexpected response format. Expected a dictionary, got {type(response)}\"\n        )\n\n    @staticmethod\n    def transform_data(\n        query: FredSearchQueryParams, data: list[dict], **kwargs: Any\n    ) -> list[FredSearchData]:\n        \"\"\"Transform data.\"\"\"\n        # pylint: disable=import-outside-toplevel\n        from numpy import nan\n        from pandas import DataFrame, Series\n\n        if not data:\n            raise EmptyDataError(\"The request was returned empty.\")\n\n        df = DataFrame(data)\n\n        if query.search_type == \"release\" and query.release_id is None:","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/fred/openbb_fred/models/search.py#L231-L267","documentation":"Raised in FredSearchFetcher.aextract_data (openbb_fred/models/search.py:249) when the parsed FRED response is neither an error dict (no 'error_code') nor a result dict (no 'count') - or is not a dict at all, e.g. a list or string. This is a defensive guard against an unexpected response shape: the helper fred_get returned something the search extractor does not know how to interpret, so it refuses to guess.","triggerScenarios":"A proxy or middleware returning HTML/text that got parsed into a string; FRED changing its JSON envelope in a way that drops 'count'; a truncated response from network interruption being parsed to a non-dict.","commonSituations":"Corporate proxies intercepting api.stlouisfed.org; pinned old openbb-fred package against a changed FRED API; flaky connections behind NAT/VPNs.","solutions":["Inspect the raw response by curling the same URL with your key to see what FRED actually returns.","Update the openbb-fred provider package (pip install -U openbb-fred) in case the parser was fixed for a new envelope.","Remove intercepting proxies/rewrites for api.stlouisfed.org.","If the response is legitimately a new format, open an issue on the OpenBB GitHub with the (redacted) payload."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"def is_search_results_payload(payload: object) -> bool:\n    \"\"\"True when the payload is a dict with the expected 'count'/'seriess' keys.\"\"\"\n    return isinstance(payload, dict) and 'count' in payload","tryCatchPattern":"from openbb_core.app.model.abstract.error import OpenBBError\n\ntry:\n    res = obb.economy.fred.search(query=q)\nexcept OpenBBError as e:\n    if 'Unexpected response format' in str(e):\n        # environment/proxy problem - surface it, do not retry blindly\n        raise RuntimeError('FRED search got an unexpected payload; check proxies/network') from e\n    raise","preventionTips":["Bypass HTTP-intercepting proxies for api.stlouisfed.org.","Pin provider versions you have tested; re-test after FRED announces API changes."],"tags":["fred","unexpected-response","network","parsing"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}