{"record":{"id":"878f45002b5bd40f","repo":"BerriAI/litellm","slug":"error-in-response-object-format-878f45","errorCode":null,"errorMessage":"Error in response object format","messagePattern":"Error in response object format","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/openai/completion/transformation.py","lineNumber":89,"sourceCode":"    ) -> None:\n        locals_: Final = locals().copy()\n        for key, value in locals_.items():\n            if key != \"self\" and value is not None:\n                setattr(self.__class__, key, value)\n\n    @classmethod\n    def get_config(cls):\n        return super().get_config()\n\n    def convert_to_chat_model_response_object(\n        self,\n        response_object: TextCompletionResponse | None = None,\n        model_response_object: ModelResponse | None = None,\n    ):\n        try:\n            ## RESPONSE OBJECT\n            if response_object is None or model_response_object is None:\n                raise ValueError(\"Error in response object format\")\n            choice_list: Final[list[Choices]] = []\n            for idx, choice in enumerate(response_object[\"choices\"]):\n                message = Message(\n                    content=choice[\"text\"],\n                    role=\"assistant\",\n                )\n                choice = Choices(\n                    finish_reason=choice[\"finish_reason\"],\n                    index=idx,\n                    message=message,\n                    logprobs=choice.get(\"logprobs\", None),\n                )\n                choice_list.append(choice)\n            model_response_object.choices = choice_list\n\n            if \"usage\" in response_object:\n                setattr(model_response_object, \"usage\", response_object[\"usage\"])\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/openai/completion/transformation.py#L71-L107","documentation":"Raised during conversion of an OpenAI text-completion (/v1/completions) raw response into litellm's chat ModelResponse format: the conversion function received None for either the raw response_object or the target model_response_object, so it refuses to continue with 'Error in response object format'. It signals that the response-transformation pipeline was invoked without a usable response payload.","triggerScenarios":"Calling litellm completion/text-completion paths (or a custom provider subclassing the OpenAI text-completion transformation) where convert_to_chat_model_response_object is invoked with response_object=None (provider returned nothing / earlier step failed silently) or model_response_object=None (caller did not pass a ModelResponse to populate).","commonSituations":"Custom or third-party OpenAI-compatible provider configs overriding transformation methods with wrong signatures after a litellm upgrade; internal regressions where an upstream HTTP failure leaves the response object unset; using litellm's transformation classes directly instead of the documented completion entry points. For stock OpenAI calls this error is rare and usually indicates a litellm bug.","solutions":["If using a custom config class, make sure you pass both response_object and a freshly built litellm.types.ModelResponse() when calling convert_to_chat_model_response_object","Use litellm.completion()/litellm.acompletion() entry points instead of invoking transformation internals directly","Pin or upgrade litellm: this class of error has historically been caused by refactors changing call signatures - check the release notes/changelog","Reproduce with the same model/payload and open a litellm GitHub issue including the traceback if it happens on stock OpenAI calls"],"exampleFix":"# before (custom config calling transformation internals)\nresult = config.convert_to_chat_model_response_object(\n    response_object=raw, model_response_object=None  # ValueError\n)\n\n# after\nfrom litellm.types.llms.openai import TextCompletionResponse\nfrom litellm.types.utils import ModelResponse\n\nresult = config.convert_to_chat_model_response_object(\n    response_object=raw,\n    model_response_object=ModelResponse(model=model_name),\n)","handlingStrategy":"try-catch","validationCode":"from litellm.types.utils import ModelResponse\n\n# If you call the transformation directly, pre-validate both inputs:\nassert raw_text_completion_response is not None, \"provider returned no response object\"\nassert isinstance(model_response_obj, ModelResponse), \"must pass a ModelResponse to populate\"\nresult = config.convert_to_chat_model_response_object(\n    response_object=raw_text_completion_response,\n    model_response_object=model_response_obj,\n)","typeGuard":"def is_convertible_response(raw) -> bool:\n    \"\"\"True when the raw completion response can be converted to chat format.\"\"\"\n    return (\n        raw is not None\n        and isinstance(raw, dict)\n        and isinstance(raw.get(\"choices\"), list)\n        and len(raw[\"choices\"]) > 0\n    )","tryCatchPattern":"try:\n    result = config.convert_to_chat_model_response_object(\n        response_object=raw, model_response_object=ModelResponse(model=model)\n    )\nexcept ValueError as e:\n    if \"response object format\" in str(e):\n        raise RuntimeError(f\"provider {provider} returned no usable completion body\") from e\n    raise","preventionTips":["Never invoke transformation internals with None payloads; assert inputs first","Pin your litellm version in requirements to avoid signature drift in transformation classes","Prefer the public litellm.completion/acompletion entry points, which construct the ModelResponse for you","When subclassing OpenAI text-completion configs, run the stock path in a test to detect contract drift after upgrades"],"tags":["response-parsing","internal","validation","completions"],"backgroundTag":"empty-response-object","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}