BerriAI/litellm · error · ValueError
Error in response object format
Error message
Error in response object format
What it means
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.
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
Example fix
# before (custom config calling transformation internals)
result = config.convert_to_chat_model_response_object(
response_object=raw, model_response_object=None # ValueError
)
# after
from litellm.types.llms.openai import TextCompletionResponse
from litellm.types.utils import ModelResponse
result = config.convert_to_chat_model_response_object(
response_object=raw,
model_response_object=ModelResponse(model=model_name),
) Defensive patterns
Strategy: try-catch
Validate before calling
from litellm.types.utils import ModelResponse
# If you call the transformation directly, pre-validate both inputs:
assert raw_text_completion_response is not None, "provider returned no response object"
assert isinstance(model_response_obj, ModelResponse), "must pass a ModelResponse to populate"
result = config.convert_to_chat_model_response_object(
response_object=raw_text_completion_response,
model_response_object=model_response_obj,
) Type guard
def is_convertible_response(raw) -> bool:
"""True when the raw completion response can be converted to chat format."""
return (
raw is not None
and isinstance(raw, dict)
and isinstance(raw.get("choices"), list)
and len(raw["choices"]) > 0
) Try / catch
try:
result = config.convert_to_chat_model_response_object(
response_object=raw, model_response_object=ModelResponse(model=model)
)
except ValueError as e:
if "response object format" in str(e):
raise RuntimeError(f"provider {provider} returned no usable completion body") from e
raise Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- AgentCore: Failed to read/parse JSON response body
- Amazon Nova Canvas requires a text prompt. Pass a non-empty…
- audience must be provided unless…
- BFL error
- Both 'sentinel_nodes' and 'service_name' are required for…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/878f45002b5bd40f.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/openai/completion/transformation.py:89
) -> None:
locals_: Final = locals().copy()
for key, value in locals_.items():
if key != "self" and value is not None:
setattr(self.__class__, key, value)
@classmethod
def get_config(cls):
return super().get_config()
def convert_to_chat_model_response_object(
self,
response_object: TextCompletionResponse | None = None,
model_response_object: ModelResponse | None = None,
):
try:
## RESPONSE OBJECT
if response_object is None or model_response_object is None:
raise ValueError("Error in response object format")
choice_list: Final[list[Choices]] = []
for idx, choice in enumerate(response_object["choices"]):
message = Message(
content=choice["text"],
role="assistant",
)
choice = Choices(
finish_reason=choice["finish_reason"],
index=idx,
message=message,
logprobs=choice.get("logprobs", None),
)
choice_list.append(choice)
model_response_object.choices = choice_list
if "usage" in response_object:
setattr(model_response_object, "usage", response_object["usage"])
View on GitHub (pinned to 77b7c6c40c)