Skip to content

Agent Zero AI framework

Fix: dirty_jason.py the _parse_number method will gracefully handle cases where the parsed string is just '+', '-', or empty, returning it as a string instead of raising a ValueError.

decib1d77cd4ef47
diff --git a/python/helpers/dirty_json.py b/python/helpers/dirty_json.py
index b65c120db..b124ba74d 100644
--- a/python/helpers/dirty_json.py
+++ b/python/helpers/dirty_json.py
@@ -252,10 +252,18 @@ class DirtyJson:
while self.current_char is not None and (self.current_char.isdigit() or self.current_char in ['-', '+', '.', 'e', 'E']):
number_str += self.current_char
self._advance()
+ # Only try to convert if number_str is a valid number
+ if number_str in ('', '+', '-'):
+ # Not a valid number, treat as string or handle error
+ return number_str.strip() # or raise ValueError("Invalid number format")
try:
return int(number_str)
except ValueError:
- return float(number_str)
+ try:
+ return float(number_str)
+ except ValueError:
+ # Not a valid number, treat as string or handle error
+ return number_str.strip() # or raise ValueError("Invalid number format")
def _parse_unquoted_string(self):
result = ""