From 8b95cd3ed25cf61e6c58488209ae95b0306d8b02 Mon Sep 17 00:00:00 2001 From: yangdx Date: Fri, 3 Oct 2025 13:46:51 +0800 Subject: [PATCH] Fix whitespace handling in _has_meaningful_content function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Preserve newlines and spaces as content • Remove .strip() call on strings • Treat all non-empty strings as meaningful • Update logic comment for clarity • Fix edge case with whitespace-only text --- litellm/litellm_core_utils/model_response_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/litellm/litellm_core_utils/model_response_utils.py b/litellm/litellm_core_utils/model_response_utils.py index 5f6fced9d44..974d12aef6f 100644 --- a/litellm/litellm_core_utils/model_response_utils.py +++ b/litellm/litellm_core_utils/model_response_utils.py @@ -84,7 +84,9 @@ def _has_meaningful_content(value: Any) -> bool: return False if isinstance(value, str): - return len(value.strip()) > 0 + # Don't strip whitespace - preserve all content including newlines, spaces, etc. + # Even pure whitespace characters like '\n' or ' ' are meaningful content + return len(value) > 0 if isinstance(value, (list, dict)): return len(value) > 0