Skip to content

Commit

Permalink
Improve error messaging (#3236)
Browse files Browse the repository at this point in the history
* Update error language and corresponding tests

* Updated another test to use the new error message
  • Loading branch information
umermansoor authored and victordibia committed Jul 30, 2024
1 parent b4122d8 commit 374483d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,7 @@ def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict
arguments = json.loads(input_string)
except json.JSONDecodeError as e:
arguments = None
content = f"Error: {e}\n You argument should follow json format."
content = f"Error: {e}\n The argument must be in JSON format."

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

# Try to execute the function
if arguments is not None:
Expand Down
6 changes: 3 additions & 3 deletions test/agentchat/test_function_and_tool_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str:
{
"tool_call_id": "1",
"role": "tool",
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n You argument should follow json format.",
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.",
},
{"tool_call_id": "2", "role": "tool", "content": "_tool_func_2: value3 value4"},
],
"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",
"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",
}

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

_function_use_message_1_error_expected_reply = {
Expand Down
4 changes: 2 additions & 2 deletions test/agentchat/test_function_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def add_num(num_to_be_added):
"name": "add_num",
"arguments": '{ "num_to_be_added": 5, given_num: 10 }',
} # should be "given_num" with quotes
assert "You argument should follow json format." in user.execute_function(func_call=wrong_json_format)[1]["content"]
assert "The argument must be in JSON format." in user.execute_function(func_call=wrong_json_format)[1]["content"]

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

Expand Down

0 comments on commit 374483d

Please sign in to comment.