BerriAI/litellm · error · BedrockError
Error setting response content: {e}. Response: {completion_r
Error message
Error setting response content: {e}. Response: {completion_response} What it means
Raised by the TwelveLabs Pegasus transform_response when it cannot assign the extracted message content onto model_response.choices[0].message - either the content was empty/None, or tool_calls already exist on the message (making content assignment invalid). It wraps this as a BedrockError echoing the full completion_response and the underlying exception, using the HTTP status code of the raw response.
Source
Thrown at litellm/llms/bedrock/chat/invoke_transformations/amazon_twelvelabs_pegasus_transformation.py:239
message_content: Final = completion_response.get("message", "")
# Extract finish reason and map to LiteLLM format
finish_reason_raw: Final = completion_response.get("finishReason", "stop")
finish_reason: Final = map_finish_reason(finish_reason_raw)
# Set the response content
try:
if (
message_content
and hasattr(model_response.choices[0], "message")
and getattr(model_response.choices[0].message, "tool_calls", None) is None
):
model_response.choices[0].message.content = message_content
model_response.choices[0].finish_reason = finish_reason
else:
raise Exception("Unable to set message content")
except Exception as e:
raise BedrockError(
message=f"Error setting response content: {e}. Response: {completion_response}",
status_code=raw_response.status_code,
)
# Calculate usage from headers
bedrock_input_tokens: Final = raw_response.headers.get("x-amzn-bedrock-input-token-count", None)
bedrock_output_tokens: Final = raw_response.headers.get("x-amzn-bedrock-output-token-count", None)
prompt_tokens: Final = int(bedrock_input_tokens or litellm.token_counter(messages=messages))
completion_tokens: Final = int(
bedrock_output_tokens
or litellm.token_counter(
text=model_response.choices[0].message.content,
count_response_tokens=True,
)
)
View on GitHub (pinned to 6c2dcb801b)
Solutions
- Inspect completion_response in the error message: an empty 'message' field means the model produced no content - check prompt and parameters.
- Avoid passing tool definitions to twelvelabs-pegasus through this legacy invoke path; use the converse route if tool use is required.
- Upgrade litellm so the newest twelvelabs transformation handles edge cases.
- Verify max_tokens and stop settings are not truncating the response before any content is generated.
Example fix
# before resp = litellm.completion(model="bedrock/us.twelvelabs-pegasus-1-0", messages=msgs, tools=tools) # after - do not send tools to twelvelabs via the invoke path resp = litellm.completion(model="bedrock/us.twelvelabs-pegasus-1-0", messages=msgs)
Defensive patterns
Strategy: validation
Validate before calling
messages = [m for m in messages if m.get("content")] # avoid empty-prompt edge cases
if max_tokens is not None and max_tokens < 8:
raise ValueError("max_tokens too small - model may return empty message content") Try / catch
from litellm.exceptions import BedrockError
try:
resp = litellm.completion(model="bedrock/us.twelvelabs-pegasus-1-0", messages=msgs)
except BedrockError as e:
if "Error setting response content" in str(e):
log.warning("empty twelvelabs response: %s", e.message)
return fallback_response()
raise Prevention
- Do not pass tools to twelvelabs-pegasus via the legacy invoke path.
- Set a sane max_tokens floor so content is not truncated to empty.
- Handle empty-content responses gracefully instead of treating them as fatal.
When it happens
Trigger: A twelvelabs-pegasus completion where the JSON parses but the 'message' field is empty, or a previous tool-call path left choices[0].message.tool_calls set so the content branch is skipped and the explicit 'Unable to set message content' exception is thrown.
Common situations: Calling twelvelabs models with tools enabled (tool_calls present), provider returning an empty message field (e.g. content filtered or max_tokens=0), or version drift in the twelvelabs response schema.
Related errors
- Error parsing response: {raw_response.text}, error: {e}
- Error parsing received text={outputText}.\nError-{e}
- Model needs to be set for bedrock
- BedrockException: Context Window Error - {error_str}
- BedrockException - {error_str} . Enable 'litellm.modify_para
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/a77072427cecf528.
Report an issue: GitHub.