BerriAI/litellm · error · HuggingFaceError

response is not in expected format

Error message

response is not in expected format - {completion_response}

What it means

Error "response is not in expected format - {completion_response}" thrown in BerriAI/litellm.

Solutions

  1. The endpoint returned an unexpected shape; inspect the logged response and confirm the task matches the model (embeddings vs similarity).

When it happens

Trigger: Thrown at litellm/llms/huggingface/embedding/transformation.py:388 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at litellm/llms/huggingface/embedding/transformation.py:388

        task: hf_tasks | None,
        optional_params: dict,
        encoding: Any,
        messages: list[AllMessageValues],
        model: str,
    ):
        if task is None:
            task = "text-generation-inference"  # default to tgi

        if task == "conversational":
            if len(completion_response["generated_text"]) > 0:
                model_response.choices[0].message.content = completion_response["generated_text"]
        elif task == "text-generation-inference":
            if (
                not isinstance(completion_response, list)
                or not isinstance(completion_response[0], dict)
                or "generated_text" not in completion_response[0]
            ):
                raise HuggingFaceError(
                    status_code=422,
                    message=f"response is not in expected format - {completion_response}",
                    headers=None,
                )

            if len(completion_response[0]["generated_text"]) > 0:
                model_response.choices[0].message.content = output_parser(completion_response[0]["generated_text"])
            ## GETTING LOGPROBS + FINISH REASON
            if "details" in completion_response[0] and "tokens" in completion_response[0]["details"]:
                model_response.choices[0].finish_reason = completion_response[0]["details"]["finish_reason"]
                sum_logprob = 0
                for token in completion_response[0]["details"]["tokens"]:
                    if token["logprob"] is not None:
                        sum_logprob += token["logprob"]
                setattr(model_response.choices[0].message, "_logprob", sum_logprob)
            if "best_of" in optional_params and optional_params["best_of"] > 1:
                if "details" in completion_response[0] and "best_of_sequences" in completion_response[0]["details"]:
                    choices_list: Final = []

View on GitHub (pinned to 77b7c6c40c)