{"record":{"id":"447e96de3011759a","repo":"BerriAI/litellm","slug":"failed-to-parse-prompt-response-for-prompt-id","errorCode":null,"errorMessage":"Failed to parse prompt response for '{prompt_id}': {e}","messagePattern":"Failed to parse prompt response for '(.+?)': (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/generic_prompt_management/generic_prompt_manager.py","lineNumber":130,"sourceCode":"        params: Final = {\n            \"prompt_id\": prompt_id,\n            **(self.additional_provider_specific_query_params or {}),\n        }\n        http_client: Final = _get_httpx_client()\n\n        try:\n            response: Final = http_client.get(\n                url,\n                params=params,\n                headers=self._get_headers(),\n            )\n\n            response.raise_for_status()\n            return response.json()\n        except httpx.HTTPError as e:\n            raise Exception(f\"Failed to fetch prompt '{prompt_id}' from API: {e}\")\n        except json.JSONDecodeError as e:\n            raise Exception(f\"Failed to parse prompt response for '{prompt_id}': {e}\")\n\n    async def async_fetch_prompt_from_api(\n        self, prompt_id: str | None, prompt_spec: PromptSpec | None\n    ) -> dict[str, Any]:\n        \"\"\"\n        Fetch a prompt from the API asynchronously.\n        \"\"\"\n        if prompt_id is None and prompt_spec is None:\n            raise ValueError(\"prompt_id or prompt_spec is required\")\n\n        url: Final = f\"{self.api_base}/beta/litellm_prompt_management\"\n        params: Final = {\n            \"prompt_id\": prompt_id,\n            **(\n                prompt_spec.litellm_params.provider_specific_query_params\n                if prompt_spec and prompt_spec.litellm_params.provider_specific_query_params\n                else {}\n            ),","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/generic_prompt_management/generic_prompt_manager.py#L112-L148","documentation":"GenericPromptManager raises this when the prompt API returned HTTP 2xx (raise_for_status passed) but response.json() raised json.JSONDecodeError — the body is not valid JSON. Typical causes are an HTML login/error page served with 200, a plain-text proxy page, or a truncated body from a misbehaving gateway.","triggerScenarios":"api_base pointing at a generic domain that serves an HTML landing page with 200; an auth proxy that redirects (followed) to an HTML sign-in page; an API gateway returning a plain-text 'OK' health string; response truncated by a proxy or size limit so JSON is malformed.","commonSituations":"Using a company domain root instead of the actual API host; SSO in front of the prompt service that returns a login page instead of a JSON error; a CDN serving a cached HTML error page with 200 status.","solutions":["Reproduce and inspect the raw body: curl -s '<api_base>/beta/litellm_prompt_management?prompt_id=<id>' | head -c 500 — if it's HTML, you're talking to the wrong endpoint.","Point api_base at the real API host/path, not a domain root or UI host.","If SSO fronts the service, configure machine-to-machine auth (api_key) so requests bypass the HTML login flow.","Check gateway/CDN rules for response rewriting on this path."],"exampleFix":"# before\ngeneric_prompt_config: {'api_base': 'https://prompts.example.com'}  # serves HTML at /\n\n# after\ngeneric_prompt_config: {'api_base': 'https://prompts.example.com/api'}  # real JSON API root","handlingStrategy":"try-catch","validationCode":"import httpx\n\nresp = httpx.get(url, params=params, headers=headers, timeout=5)\ntry:\n    data = resp.json()\nexcept ValueError:\n    raise ValueError(f'Prompt API returned non-JSON ({resp.headers.get(\"content-type\")}): {resp.text[:200]}')","typeGuard":null,"tryCatchPattern":"try:\n    data = manager.fetch_prompt_from_api(prompt_id, None)\nexcept Exception as e:\n    if 'Failed to parse prompt response' in str(e):\n        # 200 + non-JSON body: wrong endpoint/SSO page — inspect body, do not retry the same call\n        raise ConfigError('Prompt API base URL points at a non-JSON endpoint (check api_base)') from e\n    raise","preventionTips":["Verify the API returns JSON with a curl preflight before wiring prompt routing.","If SSO fronts the service, use api_key machine auth so HTML login pages are never returned.","Include a snippet of the body in your error handling to make HTML-for-JSON obvious immediately."],"tags":["prompt-management","json-parsing","http-client"],"backgroundTag":"invalid-json-response","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}