File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ def _convert_from_v1_to_chat_completions(message: AIMessage) -> AIMessage:
1515 if block_type == "text" :
1616 # Strip annotations
1717 new_content .append ({"type" : "text" , "text" : block ["text" ]})
18- elif block_type in ("reasoning" , "tool_call" ):
18+ elif block_type in ("reasoning" , "tool_call" , "invalid_tool_call" ):
1919 pass
2020 else :
2121 new_content .append (block )
Original file line number Diff line number Diff line change @@ -172,6 +172,44 @@ def test_sanitize_chat_completions_content_passthrough_string() -> None:
172172 assert _sanitize_chat_completions_content ("hello" ) == "hello"
173173
174174
175+ def test_convert_v1_message_filters_invalid_tool_call_content () -> None :
176+ """Invalid tool calls remain diagnostic metadata, not content blocks."""
177+ message = AIMessage (
178+ content = [
179+ {"type" : "text" , "text" : "Let me check." },
180+ {
181+ "type" : "invalid_tool_call" ,
182+ "id" : "call_invalid" ,
183+ "name" : "get_weather" ,
184+ "args" : '{"city":' ,
185+ "error" : "Invalid JSON" ,
186+ },
187+ ],
188+ invalid_tool_calls = [
189+ {
190+ "type" : "invalid_tool_call" ,
191+ "id" : "call_invalid" ,
192+ "name" : "get_weather" ,
193+ "args" : '{"city":' ,
194+ "error" : "Invalid JSON" ,
195+ }
196+ ],
197+ response_metadata = {"output_version" : "v1" },
198+ )
199+
200+ assert _convert_message_to_dict (message ) == {
201+ "role" : "assistant" ,
202+ "content" : "Let me check." ,
203+ "tool_calls" : [
204+ {
205+ "type" : "function" ,
206+ "id" : "call_invalid" ,
207+ "function" : {"name" : "get_weather" , "arguments" : '{"city":' },
208+ }
209+ ],
210+ }
211+
212+
175213def test_sanitize_chat_completions_content_passthrough_non_text_block () -> None :
176214 blocks = [{"type" : "image_url" , "image_url" : {"url" : "https://x/y.png" }}]
177215 assert _sanitize_chat_completions_content (blocks ) == blocks
You can’t perform that action at this time.
0 commit comments