litellm icon indicating copy to clipboard operation
litellm copied to clipboard

(edge case) fix IndexError vulnerability with Anthropic models

Open jakobdylanc opened this issue 3 months ago • 3 comments

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": []}

jakobdylanc avatar Mar 18 '24 00:03 jakobdylanc