Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: claude can not handle empty string (#11238)

yihong02572e8cca50
diff --git a/api/core/model_runtime/model_providers/anthropic/llm/llm.py b/api/core/model_runtime/model_providers/anthropic/llm/llm.py
index b24324708b0..3faf5abbe87 100644
--- a/api/core/model_runtime/model_providers/anthropic/llm/llm.py
+++ b/api/core/model_runtime/model_providers/anthropic/llm/llm.py
@@ -483,6 +483,10 @@ class AnthropicLargeLanguageModel(LargeLanguageModel):
if isinstance(message, UserPromptMessage):
message = cast(UserPromptMessage, message)
if isinstance(message.content, str):
+ # handle empty user prompt see #10013 #10520
+ # responses, ignore user prompts containing only whitespace, the Claude API can't handle it.
+ if not message.content.strip():
+ continue
message_dict = {"role": "user", "content": message.content}
prompt_message_dicts.append(message_dict)
else: