1414 InputGuardrail ,
1515 InputGuardrailTripwireTriggered ,
1616 MaxTurnsExceeded ,
17- ModelBehaviorError ,
1817 OutputGuardrail ,
1918 OutputGuardrailTripwireTriggered ,
2019 RunContextWrapper ,
@@ -149,17 +148,24 @@ async def test_tool_call_error():
149148 agent = Agent (
150149 name = "test_agent" ,
151150 model = model ,
152- tools = [get_function_tool ("foo" , "tool_result" , hide_errors = True )],
151+ tools = [get_function_tool ("foo" , "tool_result" )],
153152 )
154153
155- model .set_next_output (
156- [get_text_message ("a_message" ), get_function_tool_call ("foo" , "bad_json" )],
154+ model .add_multiple_turn_outputs (
155+ [
156+ [get_text_message ("a_message" ), get_function_tool_call ("foo" , "bad_json" )],
157+ [get_text_message ("done" )],
158+ ]
157159 )
158160
159- with pytest .raises (ModelBehaviorError ):
160- result = Runner .run_streamed (agent , input = "first_test" )
161- async for _ in result .stream_events ():
162- pass
161+ result = Runner .run_streamed (agent , input = "first_test" )
162+ async for _ in result .stream_events ():
163+ pass
164+
165+ tool_outputs = [item for item in result .new_items if item .type == "tool_call_output_item" ]
166+ assert tool_outputs , "Expected a tool output item for invalid JSON"
167+ assert "An error occurred while parsing tool arguments" in str (tool_outputs [0 ].output )
168+ assert "valid JSON" in str (tool_outputs [0 ].output )
163169
164170 assert fetch_normalized_spans () == snapshot (
165171 [
@@ -182,11 +188,20 @@ async def test_tool_call_error():
182188 "message" : "Error running tool" ,
183189 "data" : {
184190 "tool_name" : "foo" ,
185- "error" : "Invalid JSON input for tool foo: bad_json " ,
191+ "error" : "Expecting value: line 1 column 1 (char 0) " ,
186192 },
187193 },
188- "data" : {"name" : "foo" , "input" : "bad_json" },
194+ "data" : {
195+ "name" : "foo" ,
196+ "input" : "bad_json" ,
197+ "output" : (
198+ "An error occurred while parsing tool arguments. "
199+ "Please try again with valid JSON. Error: Expecting "
200+ "value: line 1 column 1 (char 0)"
201+ ),
202+ },
189203 },
204+ {"type" : "generation" },
190205 ],
191206 }
192207 ],
0 commit comments