{"record":{"id":"eece14736a06590a","repo":"BerriAI/litellm","slug":"langflow-returned-a-non-json-response-e","errorCode":null,"errorMessage":"LangFlow returned a non-JSON response: {e}","messagePattern":"LangFlow returned a non-JSON response: (.+?)","errorType":"http","errorClass":"LangFlowError","httpStatus":null,"severity":"error","filePath":"litellm/llms/langflow/chat/transformation.py","lineNumber":233,"sourceCode":"\n    def transform_response(\n        self,\n        model: str,\n        raw_response: httpx.Response,\n        model_response: ModelResponse,\n        logging_obj: LiteLLMLoggingObj,\n        request_data: dict,\n        messages: list[AllMessageValues],\n        optional_params: dict,\n        litellm_params: dict,\n        encoding: Any,\n        api_key: str | None = None,\n        json_mode: bool | None = None,\n    ) -> ModelResponse:\n        try:\n            response_json: Final = raw_response.json()\n        except Exception as e:\n            raise LangFlowError(\n                message=f\"LangFlow returned a non-JSON response: {e}\",\n                status_code=raw_response.status_code,\n            )\n\n        verbose_logger.debug(\"LangFlow response: %s\", response_json)\n\n        content: Final = self._extract_content_from_response(response_json)\n        if content is None:\n            raise LangFlowError(\n                message=(\n                    \"Could not extract a message from the LangFlow response; \"\n                    \"ensure the flow ends in a Chat Output component\"\n                ),\n                status_code=500,\n            )\n\n        message: Final = Message(content=content, role=\"assistant\")\n        choice: Final = Choices(finish_reason=\"stop\", index=0, message=message)","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/langflow/chat/transformation.py#L215-L251","documentation":"After the HTTP call to {api_base}/api/v1/run/{flow_id} returns, LiteLLM calls raw_response.json(); if the body is not valid JSON it raises LangFlowError with the upstream HTTP status code and the JSON parse exception text. Typical cause: the server returned HTML (auth portal, proxy error page, 502 gateway page) or plain text instead of the expected JSON.","triggerScenarios":"api_base points at a reverse proxy / SSO portal that returns an HTML login page; a 502/503 from a gateway in front of LangFlow; hitting a non-LangFlow server (wrong port) that answers in text; a truncated body from a timeout mid-transfer.","commonSituations":"Wrong LANGFLOW_API_BASE (e.g. pointing at the frontend port of a different service); corporate proxy intercepting the request; LangFlow behind a load balancer that errors; TLS misconfiguration returning an error page.","solutions":["Verify api_base actually reaches LangFlow: curl -i {api_base}/api/v1/run/<flow_id> and inspect Content-Type","Fix proxy/gateway issues (bypass the corporate proxy, correct the port, fix TLS) so LangFlow's JSON responses pass through","If an auth portal responds, supply the correct LangFlow api_key or whitelist the client"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"def langflow_endpoint_ok(api_base: str, api_key: str | None) -> bool:\n    import requests\n    r = requests.get(f\"{api_base.rstrip('/')}/api/v1/flows\", headers={\"Authorization\": f\"Bearer {api_key or ''}\"}, timeout=5)\n    ct = r.headers.get(\"content-type\", \"\")\n    return r.status_code < 500 and \"json\" in ct","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.completion(model=\"langflow/x\", messages=msgs)\nexcept LangFlowError as e:\n    if \"non-JSON response\" in str(e):\n        # upstream/proxy returned HTML or errored: check api_base reachability, then retry with backoff\n        if langflow_endpoint_ok(base, key):\n            retry_with_backoff(...)\n        else:\n            alert_ops(f\"LangFlow at {base} not returning JSON (status {e.status_code})\")","preventionTips":["Smoke-test the full URL (curl -i, check Content-Type: application/json) whenever api_base changes","Exclude the LangFlow host from corporate proxies/VPNs that inject HTML portals","Monitor for 5xx from gateways in front of LangFlow and alert on non-JSON content types"],"tags":["langflow","network","response-parsing"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}