@@ -38,6 +38,15 @@ async def my_mock_fn_3(
3838 return f"{ param1 } and { param2 } "
3939
4040
41+ def my_mock_fn_that_raises (
42+ param1 : int ,
43+ param2 : str = "x" ,
44+ * args : Any ,
45+ ** kwargs : Any ,
46+ ) -> str :
47+ raise RuntimeError ("Oops!" )
48+
49+
4150@pytest .mark .parametrize (
4251 ("func" , "properties" , "required" ),
4352 [
@@ -114,7 +123,7 @@ def test_function_tool_call(mock_validate: MagicMock) -> None:
114123 assert result .error is False
115124
116125
117- def test_function_tool_call_returns_error () -> None :
126+ def test_function_tool_call_returns_validation_error () -> None :
118127 """Tests a function tool call raises error at validation of params."""
119128 tool = SimpleFunctionTool (my_mock_fn_1 , desc = "mock desc" )
120129 tool_call = ToolCall (
@@ -124,10 +133,29 @@ def test_function_tool_call_returns_error() -> None:
124133
125134 result = tool (tool_call = tool_call )
126135
127- assert (
128- "Failed to execute function call: '1' is not of type 'number'"
129- in result . content
136+ expected_content = (
137+ '{"error_type": "ValidationError", "message": " \' 1 \' '
138+ "is not of type 'number' \" }"
130139 )
140+ assert expected_content == result .content
141+ assert result .error is True
142+
143+
144+ def test_function_tool_call_returns_execution_error () -> None :
145+ """Tests a function tool call raises error at validation of params."""
146+ tool = SimpleFunctionTool (my_mock_fn_that_raises , desc = "mock desc" )
147+ tool_call = ToolCall (
148+ tool_name = "my_mock_fn_that_raises" ,
149+ arguments = {"param1" : 1 , "param2" : "y" },
150+ )
151+
152+ result = tool (tool_call = tool_call )
153+
154+ expected_content = (
155+ '{"error_type": "RuntimeError", '
156+ '"message": "Internal error while executing tool: Oops!"}'
157+ )
158+ assert expected_content == result .content
131159 assert result .error is True
132160
133161
@@ -166,7 +194,7 @@ async def test_async_function_tool_call(mock_validate: MagicMock) -> None:
166194
167195
168196@pytest .mark .asyncio
169- async def test_async_function_tool_call_returns_error () -> None :
197+ async def test_async_function_tool_call_returns_validation_error () -> None :
170198 """Tests a function tool call."""
171199 tool = AsyncSimpleFunctionTool (my_mock_fn_1 , desc = "mock desc" )
172200 tool_call = ToolCall (
@@ -176,8 +204,29 @@ async def test_async_function_tool_call_returns_error() -> None:
176204
177205 result = await tool (tool_call = tool_call )
178206
179- assert (
180- "Failed to execute function call: '1' is not of type 'number'"
181- in result .content
207+ expected_content = (
208+ '{"error_type": "ValidationError", "message": "\' 1\' '
209+ "is not of type 'number'\" }"
210+ )
211+
212+ assert expected_content == result .content
213+ assert result .error is True
214+
215+
216+ @pytest .mark .asyncio
217+ async def test_async_function_tool_call_returns_execution_error () -> None :
218+ """Tests a function tool call raises error at validation of params."""
219+ tool = AsyncSimpleFunctionTool (my_mock_fn_that_raises , desc = "mock desc" )
220+ tool_call = ToolCall (
221+ tool_name = "my_mock_fn_that_raises" ,
222+ arguments = {"param1" : 1 , "param2" : "y" },
223+ )
224+
225+ result = await tool (tool_call = tool_call )
226+
227+ expected_content = (
228+ '{"error_type": "RuntimeError", '
229+ '"message": "Internal error while executing tool: Oops!"}'
182230 )
231+ assert expected_content == result .content
183232 assert result .error is True
0 commit comments