BerriAI/litellm · error · Exception

Failed to parse prompt response for

Error message

Failed to parse prompt response for '{prompt_id}': {e}

What it means

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.

Solutions

  1. 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.
  2. Point api_base at the real API host/path, not a domain root or UI host.
  3. If SSO fronts the service, configure machine-to-machine auth (api_key) so requests bypass the HTML login flow.
  4. Check gateway/CDN rules for response rewriting on this path.

Example fix

# before
generic_prompt_config: {'api_base': 'https://prompts.example.com'}  # serves HTML at /

# after
generic_prompt_config: {'api_base': 'https://prompts.example.com/api'}  # real JSON API root
Defensive patterns

Strategy: try-catch

Validate before calling

import httpx

resp = httpx.get(url, params=params, headers=headers, timeout=5)
try:
    data = resp.json()
except ValueError:
    raise ValueError(f'Prompt API returned non-JSON ({resp.headers.get("content-type")}): {resp.text[:200]}')

Try / catch

try:
    data = manager.fetch_prompt_from_api(prompt_id, None)
except Exception as e:
    if 'Failed to parse prompt response' in str(e):
        # 200 + non-JSON body: wrong endpoint/SSO page — inspect body, do not retry the same call
        raise ConfigError('Prompt API base URL points at a non-JSON endpoint (check api_base)') from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/447e96de3011759a. Report an issue: GitHub.

Appendix: source

Thrown at litellm/integrations/generic_prompt_management/generic_prompt_manager.py:130

        params: Final = {
            "prompt_id": prompt_id,
            **(self.additional_provider_specific_query_params or {}),
        }
        http_client: Final = _get_httpx_client()

        try:
            response: Final = http_client.get(
                url,
                params=params,
                headers=self._get_headers(),
            )

            response.raise_for_status()
            return response.json()
        except httpx.HTTPError as e:
            raise Exception(f"Failed to fetch prompt '{prompt_id}' from API: {e}")
        except json.JSONDecodeError as e:
            raise Exception(f"Failed to parse prompt response for '{prompt_id}': {e}")

    async def async_fetch_prompt_from_api(
        self, prompt_id: str | None, prompt_spec: PromptSpec | None
    ) -> dict[str, Any]:
        """
        Fetch a prompt from the API asynchronously.
        """
        if prompt_id is None and prompt_spec is None:
            raise ValueError("prompt_id or prompt_spec is required")

        url: Final = f"{self.api_base}/beta/litellm_prompt_management"
        params: Final = {
            "prompt_id": prompt_id,
            **(
                prompt_spec.litellm_params.provider_specific_query_params
                if prompt_spec and prompt_spec.litellm_params.provider_specific_query_params
                else {}
            ),

View on GitHub (pinned to 77b7c6c40c)