{"record":{"id":"1a0eff4003460590","repo":"BerriAI/litellm","slug":"response-is-not-in-expected-format-completion-r","errorCode":null,"errorMessage":"response is not in expected format - {completion_response}","messagePattern":"response is not in expected format - (.+?)","errorType":"exception","errorClass":"HuggingFaceError","httpStatus":422,"severity":"error","filePath":"litellm/llms/huggingface/embedding/transformation.py","lineNumber":388,"sourceCode":"        task: hf_tasks | None,\n        optional_params: dict,\n        encoding: Any,\n        messages: list[AllMessageValues],\n        model: str,\n    ):\n        if task is None:\n            task = \"text-generation-inference\"  # default to tgi\n\n        if task == \"conversational\":\n            if len(completion_response[\"generated_text\"]) > 0:\n                model_response.choices[0].message.content = completion_response[\"generated_text\"]\n        elif task == \"text-generation-inference\":\n            if (\n                not isinstance(completion_response, list)\n                or not isinstance(completion_response[0], dict)\n                or \"generated_text\" not in completion_response[0]\n            ):\n                raise HuggingFaceError(\n                    status_code=422,\n                    message=f\"response is not in expected format - {completion_response}\",\n                    headers=None,\n                )\n\n            if len(completion_response[0][\"generated_text\"]) > 0:\n                model_response.choices[0].message.content = output_parser(completion_response[0][\"generated_text\"])\n            ## GETTING LOGPROBS + FINISH REASON\n            if \"details\" in completion_response[0] and \"tokens\" in completion_response[0][\"details\"]:\n                model_response.choices[0].finish_reason = completion_response[0][\"details\"][\"finish_reason\"]\n                sum_logprob = 0\n                for token in completion_response[0][\"details\"][\"tokens\"]:\n                    if token[\"logprob\"] is not None:\n                        sum_logprob += token[\"logprob\"]\n                setattr(model_response.choices[0].message, \"_logprob\", sum_logprob)\n            if \"best_of\" in optional_params and optional_params[\"best_of\"] > 1:\n                if \"details\" in completion_response[0] and \"best_of_sequences\" in completion_response[0][\"details\"]:\n                    choices_list: Final = []","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/huggingface/embedding/transformation.py#L370-L406","documentation":"Error \"response is not in expected format - {completion_response}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/llms/huggingface/embedding/transformation.py:388 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The endpoint returned an unexpected shape; inspect the logged response and confirm the task matches the model (embeddings vs similarity)."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}