Skip to content

Commit 36ead68

Browse files
authored
Improve error messaging (#3236)
* Update error language and corresponding tests * Updated another test to use the new error message
1 parent d3d4cc0 commit 36ead68

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

autogen/agentchat/conversable_agent.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@ def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict
22342234
arguments = json.loads(input_string)
22352235
except json.JSONDecodeError as e:
22362236
arguments = None
2237-
content = f"Error: {e}\n You argument should follow json format."
2237+
content = f"Error: {e}\n The argument must be in JSON format."
22382238

22392239
# Try to execute the function
22402240
if arguments is not None:
@@ -2291,7 +2291,7 @@ async def a_execute_function(self, func_call):
22912291
arguments = json.loads(input_string)
22922292
except json.JSONDecodeError as e:
22932293
arguments = None
2294-
content = f"Error: {e}\n You argument should follow json format."
2294+
content = f"Error: {e}\n The argument must be in JSON format."
22952295

22962296
# Try to execute the function
22972297
if arguments is not None:

test/agentchat/test_function_and_tool_calling.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str:
9494
{
9595
"tool_call_id": "1",
9696
"role": "tool",
97-
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n You argument should follow json format.",
97+
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.",
9898
},
9999
{"tool_call_id": "2", "role": "tool", "content": "_tool_func_2: value3 value4"},
100100
],
101-
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n You argument should follow json format.\n\n_tool_func_2: value3 value4",
101+
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.\n\n_tool_func_2: value3 value4",
102102
}
103103

104104
_tool_use_message_1_error_expected_reply = {
@@ -154,7 +154,7 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str:
154154
_function_use_message_1_bad_json_expected_reply = {
155155
"name": "_tool_func_1",
156156
"role": "function",
157-
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n You argument should follow json format.",
157+
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.",
158158
}
159159

160160
_function_use_message_1_error_expected_reply = {

test/agentchat/test_function_call.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def add_num(num_to_be_added):
115115
"name": "add_num",
116116
"arguments": '{ "num_to_be_added": 5, given_num: 10 }',
117117
} # should be "given_num" with quotes
118-
assert "You argument should follow json format." in user.execute_function(func_call=wrong_json_format)[1]["content"]
118+
assert "The argument must be in JSON format." in user.execute_function(func_call=wrong_json_format)[1]["content"]
119119

120120
# function execution error with wrong arguments passed
121121
wrong_args = {"name": "add_num", "arguments": '{ "num_to_be_added": 5, "given_num": 10 }'}
@@ -174,7 +174,7 @@ async def add_num(num_to_be_added):
174174
"arguments": '{ "num_to_be_added": 5, given_num: 10 }',
175175
} # should be "given_num" with quotes
176176
assert (
177-
"You argument should follow json format."
177+
"The argument must be in JSON format."
178178
in (await user.a_execute_function(func_call=wrong_json_format))[1]["content"]
179179
)
180180

0 commit comments

Comments
 (0)