litellm
litellm copied to clipboard
(edge case) fix IndexError vulnerability with Anthropic models
The following error occurs with Anthropic models:
Traceback (most recent call last):
File "/home/jakobdylanc/.local/lib/python3.11/site-packages/litellm/llms/prompt_templates/factory.py", line 696, in anthropic_messages_pt
if new_messages[0]["role"] != "user":
~~~~~~~~~~~~^^^
IndexError: list index out of range
When passing a message object with "content" as an empty list:
{"role": "user", "content": []}