Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix(core): handle empty content in Anthropic response gracefully (#9345)

Kian Jones14ef479e7086
diff --git a/letta/llm_api/anthropic_client.py b/letta/llm_api/anthropic_client.py
index c645c2ce3..999c478ee 100644
--- a/letta/llm_api/anthropic_client.py
+++ b/letta/llm_api/anthropic_client.py
@@ -1182,7 +1182,23 @@ class AnthropicClient(LLMClientBase):
redacted_reasoning_content = content_part.data
else:
- raise RuntimeError("Unexpected empty content in response")
+ # Log the full response for debugging
+ logger.error(
+ "[Anthropic] Received response with empty content. Response ID: %s, Model: %s, Stop reason: %s, Full response: %s",
+ response.id,
+ response.model,
+ response.stop_reason,
+ json.dumps(response_data),
+ )
+ raise LLMServerError(
+ message=f"LLM provider returned empty content in response (ID: {response.id}, model: {response.model}, stop_reason: {response.stop_reason})",
+ code=ErrorCode.INTERNAL_SERVER_ERROR,
+ details={
+ "response_id": response.id,
+ "model": response.model,
+ "stop_reason": response.stop_reason,
+ },
+ )
assert response.role == "assistant"
choice = Choice(