{"record":{"id":"a77072427cecf528","repo":"BerriAI/litellm","slug":"error-setting-response-content-e-response-co","errorCode":null,"errorMessage":"Error setting response content: {e}. Response: {completion_response}","messagePattern":"Error setting response content: (.+?)\\. Response: (.+?)","errorType":"http","errorClass":"BedrockError","httpStatus":null,"severity":"error","filePath":"litellm/llms/bedrock/chat/invoke_transformations/amazon_twelvelabs_pegasus_transformation.py","lineNumber":239,"sourceCode":"        message_content: Final = completion_response.get(\"message\", \"\")\n\n        # Extract finish reason and map to LiteLLM format\n        finish_reason_raw: Final = completion_response.get(\"finishReason\", \"stop\")\n        finish_reason: Final = map_finish_reason(finish_reason_raw)\n\n        # Set the response content\n        try:\n            if (\n                message_content\n                and hasattr(model_response.choices[0], \"message\")\n                and getattr(model_response.choices[0].message, \"tool_calls\", None) is None\n            ):\n                model_response.choices[0].message.content = message_content\n                model_response.choices[0].finish_reason = finish_reason\n            else:\n                raise Exception(\"Unable to set message content\")\n        except Exception as e:\n            raise BedrockError(\n                message=f\"Error setting response content: {e}. Response: {completion_response}\",\n                status_code=raw_response.status_code,\n            )\n\n        # Calculate usage from headers\n        bedrock_input_tokens: Final = raw_response.headers.get(\"x-amzn-bedrock-input-token-count\", None)\n        bedrock_output_tokens: Final = raw_response.headers.get(\"x-amzn-bedrock-output-token-count\", None)\n\n        prompt_tokens: Final = int(bedrock_input_tokens or litellm.token_counter(messages=messages))\n\n        completion_tokens: Final = int(\n            bedrock_output_tokens\n            or litellm.token_counter(\n                text=model_response.choices[0].message.content,\n                count_response_tokens=True,\n            )\n        )\n","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/bedrock/chat/invoke_transformations/amazon_twelvelabs_pegasus_transformation.py#L221-L257","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nresp = litellm.completion(model=\"bedrock/us.twelvelabs-pegasus-1-0\", messages=msgs, tools=tools)\n\n# after - do not send tools to twelvelabs via the invoke path\nresp = litellm.completion(model=\"bedrock/us.twelvelabs-pegasus-1-0\", messages=msgs)","handlingStrategy":"validation","validationCode":"messages = [m for m in messages if m.get(\"content\")]  # avoid empty-prompt edge cases\nif max_tokens is not None and max_tokens < 8:\n    raise ValueError(\"max_tokens too small - model may return empty message content\")","typeGuard":null,"tryCatchPattern":"from litellm.exceptions import BedrockError\ntry:\n    resp = litellm.completion(model=\"bedrock/us.twelvelabs-pegasus-1-0\", messages=msgs)\nexcept BedrockError as e:\n    if \"Error setting response content\" in str(e):\n        log.warning(\"empty twelvelabs response: %s\", e.message)\n        return fallback_response()\n    raise","preventionTips":["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."],"tags":["aws","bedrock","twelvelabs","response-mapping","tools"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}