Fix: litellm assistant message empty content convert from empty list to empty string #117
+3
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
background: assistant message with tool_calls and empty list content can cause litellm crash for Third-Party Models such as OpenAI, DeepSeek, ollama models, etc.
fix: change empty list content to empty string
messages before fix:
[{'role': 'developer', 'content': 'I can answer your questions about the time and weather in a city.\n\nYou are an agent. Your internal name is "weather_time_agent".\n\n The description about you is "Agent to answer questions about the time and weather in a city."'}, {'role': 'user', 'content': 'what time is it in new york?'}, {'role': 'assistant', 'content': [], 'tool_calls': [dict(function=dict(arguments='{"city": "New York"}', name='get_current_time'), id='f61b9dcb-592a-4a3d-9598-1006bc0cfedf', type='function')]}, {'role': 'tool', 'tool_call_id': 'f61b9dcb-592a-4a3d-9598-1006bc0cfedf', 'content': '{"status": "success", "report": "The current time in New York is 2025-04-12 07:35:46 EDT-0400"}'}]messages after fix -- messages[2]['content']
[{'role': 'developer', 'content': 'I can answer your questions about the time and weather in a city.\n\nYou are an agent. Your internal name is "weather_time_agent".\n\n The description about you is "Agent to answer questions about the time and weather in a city."'}, {'role': 'user', 'content': 'what time is it in new york?'}, {'role': 'assistant', 'content': '', 'tool_calls': [dict(function=dict(arguments='{"city": "New York"}', name='get_current_time'), id='f61b9dcb-592a-4a3d-9598-1006bc0cfedf', type='function')]}, {'role': 'tool', 'tool_call_id': 'f61b9dcb-592a-4a3d-9598-1006bc0cfedf', 'content': '{"status": "success", "report": "The current time in New York is 2025-04-12 07:35:46 EDT-0400"}'}]