From 8a295c48dda0ee95aa8d47601a2e705966f5de45 Mon Sep 17 00:00:00 2001 From: Catherine Renelle <32781029+catrenelle@users.noreply.github.com> Date: Wed, 11 Feb 2026 21:26:32 -0500 Subject: [PATCH] Handle empty string AI responses as fallback The null-coalescing operator only caught null, not empty/whitespace responses. When Ollama returns empty content (common when the model hesitates between tool calling and text), the empty string was saved as the assistant message. Now uses IsNullOrWhiteSpace to catch both. Co-Authored-By: Claude Opus 4.6 --- src/Purrse.Api/Services/ChatService.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Purrse.Api/Services/ChatService.cs b/src/Purrse.Api/Services/ChatService.cs index 0a94c0c..87f41d6 100644 --- a/src/Purrse.Api/Services/ChatService.cs +++ b/src/Purrse.Api/Services/ChatService.cs @@ -248,7 +248,9 @@ public class ChatService : IChatService } else { - var rawContent = response?.Message?.Content ?? "I'm sorry, I couldn't process that request."; + var rawContent = string.IsNullOrWhiteSpace(response?.Message?.Content) + ? "I'm sorry, I couldn't process that request." + : response!.Message!.Content; // If the model responded without calling any tools on the first attempt // AND there are no prior tool results AND no page context data, it