Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

fix: Catch bad LLM function call

Clémence Lesné737566f2e130
diff --git a/models/message.py b/models/message.py
index d77efa5..214553b 100644
--- a/models/message.py
+++ b/models/message.py
@@ -89,7 +89,14 @@ class ToolModel(BaseModel):
logger = build_logger(__name__)
name = self.function_name
- args = json.loads(self.function_arguments)
+
+ try:
+ args = json.loads(self.function_arguments)
+ except json.JSONDecodeError:
+ logger.warn(
+ f"Error decoding JSON args for function {name}: {self.function_arguments}"
+ )
+ return f"Bad JSON format, impossible to execute function {name}"
try:
res = await getattr(plugins, name)(**args)