Skip to content

Commit 9a581fc

Browse files
committed
test(litellm): cover None and empty-string tool-call arguments
Add regression tests for the lite_llm._message_to_generate_content_response fallback path: tool calls with arguments=None or arguments="" should produce a function call with empty args (rather than being skipped as malformed JSON). The or {} fallback in the fix already handles these, but the behavior was previously untested.
1 parent f72c72d commit 9a581fc

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

tests/unittests/models/test_litellm.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5012,3 +5012,60 @@ def test_message_to_generate_content_response_all_malformed_tool_calls():
50125012
response = _message_to_generate_content_response(message)
50135013
assert response.content.role == "model"
50145014
assert len(response.content.parts) == 0
5015+
5016+
5017+
5018+
def test_message_to_generate_content_response_tool_call_none_arguments():
5019+
"""Tool call with arguments=None should produce a function call with empty args."""
5020+
message = ChatCompletionAssistantMessage(
5021+
role="assistant",
5022+
content=None,
5023+
tool_calls=[
5024+
ChatCompletionMessageToolCall(
5025+
type="function",
5026+
id="call_none_args",
5027+
function=Function(
5028+
name="no_args_tool",
5029+
arguments=None,
5030+
),
5031+
),
5032+
],
5033+
)
5034+
5035+
response = _message_to_generate_content_response(message)
5036+
assert response.content.role == "model"
5037+
function_parts = [
5038+
p for p in response.content.parts if p.function_call is not None
5039+
]
5040+
assert len(function_parts) == 1
5041+
assert function_parts[0].function_call.name == "no_args_tool"
5042+
assert function_parts[0].function_call.id == "call_none_args"
5043+
assert dict(function_parts[0].function_call.args) == {}
5044+
5045+
5046+
def test_message_to_generate_content_response_tool_call_empty_string_arguments():
5047+
"""Tool call with arguments='' should produce a function call with empty args."""
5048+
message = ChatCompletionAssistantMessage(
5049+
role="assistant",
5050+
content=None,
5051+
tool_calls=[
5052+
ChatCompletionMessageToolCall(
5053+
type="function",
5054+
id="call_empty_args",
5055+
function=Function(
5056+
name="empty_args_tool",
5057+
arguments="",
5058+
),
5059+
),
5060+
],
5061+
)
5062+
5063+
response = _message_to_generate_content_response(message)
5064+
assert response.content.role == "model"
5065+
function_parts = [
5066+
p for p in response.content.parts if p.function_call is not None
5067+
]
5068+
assert len(function_parts) == 1
5069+
assert function_parts[0].function_call.name == "empty_args_tool"
5070+
assert function_parts[0].function_call.id == "call_empty_args"
5071+
assert dict(function_parts[0].function_call.args) == {}

0 commit comments

Comments
 (0)