From 14ef479e7086f8f07ab6c0c8df0609726bdb7084 Mon Sep 17 00:00:00 2001 From: Kian Jones <11655409+kianjones9@users.noreply.github.com> Date: Fri, 6 Feb 2026 17:26:33 -0800 Subject: [PATCH] fix(core): handle empty content in Anthropic response gracefully (#9345) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes Datadog issue a47619fa-d5b8-11f0-9fd7-da7ad0900000 Handle empty content in Anthropic responses gracefully by replacing RuntimeError with LLMServerError. Now logs detailed debugging information (response ID, model, stop_reason) and returns a user-friendly error instead of crashing. 🐾 Generated with [Letta Code](https://letta.com) Co-authored-by: Letta --- letta/llm_api/anthropic_client.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/letta/llm_api/anthropic_client.py b/letta/llm_api/anthropic_client.py index c645c2ce..999c478e 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(