From f178b5abbbed0ce8a5b383e89ab7ad132281a49d Mon Sep 17 00:00:00 2001
From: Ashwin <ashwin.mirskar@gmail.com>
Date: Mon, 8 Apr 2024 00:42:37 +0530
Subject: [PATCH] Fix ErrorHandling: adding err handling in eval_utils
 default_parser for correctness (#12624)

---
 .../llama_index/core/evaluation/eval_utils.py         | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/llama-index-core/llama_index/core/evaluation/eval_utils.py b/llama-index-core/llama_index/core/evaluation/eval_utils.py
index 3e69039691..76f719e91d 100644
--- a/llama-index-core/llama_index/core/evaluation/eval_utils.py
+++ b/llama-index-core/llama_index/core/evaluation/eval_utils.py
@@ -213,7 +213,16 @@ def default_parser(eval_response: str) -> Tuple[Optional[float], Optional[str]]:
     Returns:
         Tuple[float, str]: A tuple containing the score as a float and the reasoning as a string.
     """
+    if not eval_response.strip():
+        # Return None or default values if the response is empty
+        return None, "No response"
+
     score_str, reasoning_str = eval_response.split("\n", 1)
-    score = float(score_str)
+
+    try:
+        score = float(score_str)
+    except ValueError:
+        score = None
+
     reasoning = reasoning_str.lstrip("\n")
     return score, reasoning
-- 
GitLab