# List index out of range msg\_i

**URL:** <https://community.crewai.com/t/list-index-out-of-range-msg-i/5612>\
**Category:** CrewAI Community Support\
**Tags:** crewai\
**Created:** [May 2, 2025, 8:02am UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612 "2025-05-02T08:02:59Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sodoherty](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/sodoherty/32/2431_2.png) [@sodoherty](https://community.crewai.com/u/sodoherty)\
**Post date:** [May 2, 2025, 8:02am UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/1 "2025-05-02T08:02:59Z")

</div>

I posted earlier but it’s closed.

Tools are failing with list index out of range when using Ollama in CrewAI. Debugging it appears to be happening in litellm.

I posted a bug for it.

> <https://github.com/BerriAI/litellm/issues/10499>
>
> \### What happened?
> 
> I'm using CrewAI which is generating this error: 
> 
> \`\`\`
> ollam…a\_pt
> tool\_calls = messages\[msg\_i\].get("tool\_calls")
> ~~~~~~~~ ^^^^^^^
> IndexError: list index out of range
> \`\`\`
> 
> Debugging the issue is in \`factory.py\` on the last line of this block: 
> 
> \`\`\`
> assistant\_content\_str = ""
> \## MERGE CONSECUTIVE ASSISTANT CONTENT ##
> while msg\_i \< len(messages) and messages\[msg\_i\]\["role"\] == "assistant":
> assistant\_content\_str += convert\_content\_list\_to\_str(messages\[msg\_i\])
> msg\_i += 1
> 
> tool\_calls = messages\[msg\_i\].get("tool\_calls")
> \`\`\`
> 
> My \`messages\` array is 4 items, but \`msg\_i\` is being set to 4. Your \`msg += 1\` should happen after the tool\_calls is set maybe?
> 
> crewai 0.118.0 is using litellm 1.67.1. I also tested with 1.67.5
> 
> \### Relevant log output
> 
> \`\`\`shell
> project\_name/.venv/bin/python -X pycache\_prefix=/Users/user\_home/Library/Caches/JetBrains/PyCharm2025.1/cpython-cache /Applications/PyCharm.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 50105 --file project\_name/run\_crew.py research\_crew 
> Connected to pydev debugger (build 251.23774.444)
> project\_name/.venv/lib/python3.11/site-packages/pydantic/\_internal/\_generate\_schema.py:623: UserWarning: \<built-in function callable\> is not a Python type (it may be an instance of an object), Pydantic will allow any object with no validation since we cannot even enforce that the input is an instance of the given type. To get rid of this error wrap the type with \`pydantic.SkipValidation\`.
> warn(
> 
> Using Tool: DuckDuckGo Search
> 
> 
> LiteLLM.Info: If you need to debug this error, use \`litellm.\_turn\_on\_debug()'.
> 
> 2025-05-02 07:34:29,858 - 8651066496 - llm.py-llm:903 - ERROR: LiteLLM call failed: litellm.APIConnectionError: list index out of range
> Traceback (most recent call last):
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/main.py", line 2870, in completion
> response = base\_llm\_http\_handler.completion(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/llms/custom\_httpx/llm\_http\_handler.py", line 269, in completion
> data = provider\_config.transform\_request(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/llms/ollama/completion/transformation.py", line 322, in transform\_request
> modified\_prompt = ollama\_pt(model=model, messages=messages)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/litellm\_core\_utils/prompt\_templates/factory.py", line 229, in ollama\_pt
> tool\_calls = messages\[msg\_i\].get("tool\_calls")
> ~~~~~~~~ ^^^^^^^
> IndexError: list index out of range
> 
> Traceback (most recent call last):
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/main.py", line 2870, in completion
> response = base\_llm\_http\_handler.completion(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/llms/custom\_httpx/llm\_http\_handler.py", line 269, in completion
> data = provider\_config.transform\_request(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/llms/ollama/completion/transformation.py", line 322, in transform\_request
> modified\_prompt = ollama\_pt(model=model, messages=messages)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/litellm\_core\_utils/prompt\_templates/factory.py", line 229, in ollama\_pt
> tool\_calls = messages\[msg\_i\].get("tool\_calls")
> ~~~~~~~~ ^^^^^^^
> IndexError: list index out of range
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/crew.py", line 649, in kickoff
> result = self.\_run\_sequential\_process()
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/crew.py", line 761, in \_run\_sequential\_process
> return self.\_execute\_tasks(self.tasks)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/crew.py", line 864, in \_execute\_tasks
> task\_output = task.execute\_sync(
> ^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/task.py", line 347, in execute\_sync
> return self.\_execute\_core(agent, context, tools)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/task.py", line 491, in \_execute\_core
> raise e # Re-raise the exception after emitting the event
> ^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/task.py", line 411, in \_execute\_core
> result = agent.execute\_task(
> ^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/agent.py", line 319, in execute\_task
> raise e
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/agent.py", line 295, in execute\_task
> result = self.\_execute\_without\_timeout(task\_prompt, task)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/agent.py", line 399, in \_execute\_without\_timeout
> return self.agent\_executor.invoke(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/agents/crew\_agent\_executor.py", line 123, in invoke
> raise e
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/agents/crew\_agent\_executor.py", line 112, in invoke
> formatted\_answer = self.\_invoke\_loop()
> ^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/agents/crew\_agent\_executor.py", line 208, in \_invoke\_loop
> raise e
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/agents/crew\_agent\_executor.py", line 155, in \_invoke\_loop
> answer = get\_llm\_response(
> ^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/utilities/agent\_utils.py", line 156, in get\_llm\_response
> raise e
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/utilities/agent\_utils.py", line 147, in get\_llm\_response
> answer = llm.call(
> ^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/llm.py", line 888, in call
> return self.\_handle\_non\_streaming\_response(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/crewai/llm.py", line 727, in \_handle\_non\_streaming\_response
> response = litellm.completion(\*\*params)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/utils.py", line 1247, in wrapper
> raise e
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/utils.py", line 1125, in wrapper
> result = original\_function(\*args, \*\*kwargs)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/main.py", line 3182, in completion
> raise exception\_type(
> ^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/litellm\_core\_utils/exception\_mapping\_utils.py", line 2214, in exception\_type
> raise e
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/litellm\_core\_utils/exception\_mapping\_utils.py", line 2190, in exception\_type
> raise APIConnectionError(
> litellm.exceptions.APIConnectionError: litellm.APIConnectionError: list index out of range
> Traceback (most recent call last):
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/main.py", line 2870, in completion
> response = base\_llm\_http\_handler.completion(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/llms/custom\_httpx/llm\_http\_handler.py", line 269, in completion
> data = provider\_config.transform\_request(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/llms/ollama/completion/transformation.py", line 322, in transform\_request
> modified\_prompt = ollama\_pt(model=model, messages=messages)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/litellm\_core\_utils/prompt\_templates/factory.py", line 229, in ollama\_pt
> tool\_calls = messages\[msg\_i\].get("tool\_calls")
> ~~~~~~~~ ^^^^^^^
> IndexError: list index out of range
> 
> python-BaseException
> Error during LLM call: litellm.APIConnectionError: list index out of range
> Traceback (most recent call last):
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/main.py", line 2870, in completion
> response = base\_llm\_http\_handler.completion(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/llms/custom\_httpx/llm\_http\_handler.py", line 269, in completion
> data = provider\_config.transform\_request(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/llms/ollama/completion/transformation.py", line 322, in transform\_request
> modified\_prompt = ollama\_pt(model=model, messages=messages)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/litellm\_core\_utils/prompt\_templates/factory.py", line 229, in ollama\_pt
> tool\_calls = messages\[msg\_i\].get("tool\_calls")
> ~~~~~~~~ ^^^^^^^
> IndexError: list index out of range
> 
> An unknown error occurred. Please check the details below.
> Error details: litellm.APIConnectionError: list index out of range
> Traceback (most recent call last):
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/main.py", line 2870, in completion
> response = base\_llm\_http\_handler.completion(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/llms/custom\_httpx/llm\_http\_handler.py", line 269, in completion
> data = provider\_config.transform\_request(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/llms/ollama/completion/transformation.py", line 322, in transform\_request
> modified\_prompt = ollama\_pt(model=model, messages=messages)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "project\_name/.venv/lib/python3.11/site-packages/litellm/litellm\_core\_utils/prompt\_templates/factory.py", line 229, in ollama\_pt
> tool\_calls = messages\[msg\_i\].get("tool\_calls")
> ~~~~~~~~ ^^^^^^^
> IndexError: list index out of range
> 
> 
> Process finished with exit code 1
> \`\`\`
> 
> \### Are you a ML Ops Team?
> 
> No
> 
> \### What LiteLLM version are you on ?
> 
> v1.67.5
> 
> \### Twitter / LinkedIn details
> 
> \_No response\_

---

<div class="post-metadata">

**Author:** ![Victor\_Lobaco](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/victor_lobaco/32/2346_2.png) [@Victor\_Lobaco](https://community.crewai.com/u/Victor_Lobaco)\
**Post date:** [May 3, 2025, 5:46am UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/2 "2025-05-03T05:46:31Z")

</div>

The same happens here with ollama 0.6.6 and 0.6.7. I’m using crewai==0.118.0 and crewai-tools==0.43.0.

ERROR:root:LiteLLM call failed: litellm.APIConnectionError: list index out of range  
Traceback (most recent call last):  
File “d:\git\AI\_Agents.venv\Lib\site-packages\litellm\main.py”, line 2870, in completion  
response = base\_llm\_http\_handler.completion(  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “d:\git\AI\_Agents.venv\Lib\site-packages\litellm\llms\custom\_httpx\llm\_http\_handler.py”, line 269, in completion  
data = provider\_config.transform\_request(  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “d:\git\AI\_Agents.venv\Lib\site-packages\litellm\llms\ollama\completion\transformation.py”, line 322, in transform\_request  
modified\_prompt = ollama\_pt(model=model, messages=messages)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “d:\git\AI\_Agents.venv\Lib\site-packages\litellm\litellm\_core\_utils\prompt\_templates\factory.py”, line 229, in ollama\_pt  
tool\_calls = messages[msg\_i].get(“tool\_calls”)  
~~~~~~~~ ^^^^^^^  
IndexError: list index out of range

Error during LLM call: litellm.APIConnectionError: list index out of range  
Traceback (most recent call last):  
File “d:\git\AI\_Agents.venv\Lib\site-packages\litellm\main.py”, line 2870, in completion  
response = base\_llm\_http\_handler.completion(  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “d:\git\AI\_Agents.venv\Lib\site-packages\litellm\llms\custom\_httpx\llm\_http\_handler.py”, line 269, in completion  
data = provider\_config.transform\_request(  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “d:\git\AI\_Agents.venv\Lib\site-packages\litellm\llms\ollama\completion\transformation.py”, line 322, in transform\_request  
modified\_prompt = ollama\_pt(model=model, messages=messages)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “d:\git\AI\_Agents.venv\Lib\site-packages\litellm\litellm\_core\_utils\prompt\_templates\factory.py”, line 229, in ollama\_pt  
tool\_calls = messages[msg\_i].get(“tool\_calls”)  
~~~~~~~~ ^^^^^^^  
IndexError: list index out of range

An unknown error occurred. Please check the details below.  
Error details: litellm.APIConnectionError: list index out of range  
Traceback (most recent call last):  
File “d:\git\AI\_Agents.venv\Lib\site-packages\litellm\main.py”, line 2870, in completion  
response = base\_llm\_http\_handler.completion(  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “d:\git\AI\_Agents.venv\Lib\site-packages\litellm\llms\custom\_httpx\llm\_http\_handler.py”, line 269, in completion  
data = provider\_config.transform\_request(  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “d:\git\AI\_Agents.venv\Lib\site-packages\litellm\llms\ollama\completion\transformation.py”, line 322, in transform\_request  
modified\_prompt = ollama\_pt(model=model, messages=messages)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “d:\git\AI\_Agents.venv\Lib\site-packages\litellm\litellm\_core\_utils\prompt\_templates\factory.py”, line 229, in ollama\_pt  
tool\_calls = messages[msg\_i].get(“tool\_calls”)  
~~~~~~~~ ^^^^^^^  
IndexError: list index out of range

---

<div class="post-metadata">

**Author:** ![Julien](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/julien/32/3558_2.png) [@Julien](https://community.crewai.com/u/Julien)\
**Post date:** [May 3, 2025, 4:32pm UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/3 "2025-05-03T16:32:04Z")

</div>

Same here on mac os 15.4.1  
crewai==0.118.0  
crewai-tools==0.42.2  
ollama==0.4.8  
I’m trying to use DOCXSearchTool

Let me know if u found a fix 🙂

---

<div class="post-metadata">

**Author:** ![Matthew](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Matthew](https://community.crewai.com/u/Matthew)\
**Post date:** [May 3, 2025, 6:04pm UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/4 "2025-05-03T18:04:01Z")

</div>

Hey @sodoherty - here is what I found on this issue, I also I found a temp solution.. maybe 👇🏻..

> [@fireNew ollama model qwen3:8b fire](https://community.crewai.com/t/new-ollama-model-qwen3-8b/5559/7):
>
> FYI Crewai Community There is a bug bug with Qwen3 here is the information Bug Report: IndexError in litellm when CrewAI Agent with Tools uses Ollama/Qwen Affected Libraries: crewai, litellm LLM Provider: Ollama Model: qwen3:4b (or specific Qwen 1.5 variant used) Description: When using CrewAI with an agent configured to use an Ollama model (specifically tested with qwen3) via litellm, an IndexError: list index out of range occurs within litellm’s Ollama prompt templating logic. This er…

---

<div class="post-metadata">

**Author:** ![Dom](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/dom/32/3583_2.png) [@Dom](https://community.crewai.com/u/Dom)\
**Post date:** [May 6, 2025, 6:27pm UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/5 "2025-05-06T18:27:25Z")

</div>

I received quite similar error but having tools assigned on task level not agent level. Removing out the tools from task definition helped me finish the crew but I cannot use tools.

LiteLLM 1.67.1  
CrewAI 0.118.0  
Python 3.12  
Windows  
Ollama 0.68; gemma3:12b

---

<div class="post-metadata">

**Author:** ![Giangi\_Sacco](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/giangi_sacco/32/3594_2.png) [@Giangi\_Sacco](https://community.crewai.com/u/Giangi_Sacco)\
**Post date:** [May 8, 2025, 6:08pm UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/7 "2025-05-08T18:08:22Z")

</div>

here is the snippet of the offending part in factory.py

> ```
> while msg_i < len(messages) and messages[msg_i]["role"] == "assistant":
> assistant_content_str += convert_content_list_to_str(messages[msg_i])
> msg_i += 1
> tool_calls = messages[msg_i].get("tool_calls")
> 
> ```

My guess is that is either a bug or when the second condition is verified there was (not anymore) another element in messages, I fixed by adding a check and break right after the msg\_i is increased

> ```
> while msg_i < len(messages) and messages[msg_i]["role"] == "assistant":
> assistant_content_str += convert_content_list_to_str(messages[msg_i])
> msg_i += 1
> if msg_i == len(messages):
> break
> tool_calls = messages[msg_i].get("tool_calls")
> 
> ```

---

<div class="post-metadata">

**Author:** ![Abcfsa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/abcfsa/32/3603_2.png) [@Abcfsa](https://community.crewai.com/u/Abcfsa)\
**Post date:** [May 8, 2025, 6:16pm UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/8 "2025-05-08T18:16:53Z")

</div>

I encountered a similar problem using Ollama 0.6.8,Crewai 0.119.0,model is gwen3:8b  
I checked the bugged part in factory.py and found that the “assistant” messages are handled differently with the “user” and “system” messages -  
This is the “user” part:

> ```
> while msg_i < len(messages) and messages[msg_i]["role"] in user_message_types:
> msg_content = messages[msg_i].get("content")
> if msg_content:
> if isinstance(msg_content, list):
> for m in msg_content:
> if m.get("type", "") == "image_url":
> if isinstance(m["image_url"], str):
> images.append(m["image_url"])
> elif isinstance(m["image_url"], dict):
> images.append(m["image_url"]["url"])
> elif m.get("type", "") == "text":
> user_content_str += m["text"]
> else:
> # Tool message content will always be a string
> user_content_str += msg_content
> 
> msg_i += 1
> 
> ```

Notice where the msg\_i +=1 is located at;and this is the “assistant” part:

> ```
> while msg_i < len(messages) and messages[msg_i]["role"] == "assistant":
> assistant_content_str += convert_content_list_to_str(messages[msg_i])
> msg_i += 1
>     
> tool_calls = messages[msg_i].get("tool_calls")
> ollama_tool_calls = []
> if tool_calls:
> for call in tool_calls:
> call_id: str = call["id"]
> function_name: str = call["function"]["name"]
> arguments = json.loads(call["function"]["arguments"])
> 
> ollama_tool_calls.append(
> {
> "id": call_id,
> "type": "function",
> "function": {
> "name": function_name,
> "arguments": arguments,
> },
> }
> )
> 
> if ollama_tool_calls:
> assistant_content_str += (
> f"Tool Calls: {json.dumps(ollama_tool_calls, indent=2)}"
> )
> msg_i += 1
> 
> ```

So I changed the “assistant” part so that it aligns with the “user” part:

> ```
> while msg_i < len(messages) and messages[msg_i]["role"] == "assistant":
> assistant_content_str += convert_content_list_to_str(messages[msg_i])
> # msg_i += 1
>    
> tool_calls = messages[msg_i].get("tool_calls")
> ollama_tool_calls = []
> ...
> if ollama_tool_calls:
> assistant_content_str += (
> f"Tool Calls: {json.dumps(ollama_tool_calls, indent=2)}"
> )
> 
> msg_i += 1           
> 
> ```

And it worked well then on.This seems to be a bug within the factory.py file,which is a litellm bug to be solved.

---

<div class="post-metadata">

**Author:** ![tonykipkemboi](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/tonykipkemboi/32/4070_2.png) [@tonykipkemboi](https://community.crewai.com/u/tonykipkemboi)\
**Post date:** [May 8, 2025, 6:34pm UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/9 "2025-05-08T18:34:15Z")

</div>

Current work around also apart from the fix above, is to use crewai version `0.118.0`.

We’ve raised the issue with LiteLLM and there seems to be a PR to fix this as well on their end waiting to be merged.

---

<div class="post-metadata">

**Author:** ![Dom](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/dom/32/3583_2.png) [@Dom](https://community.crewai.com/u/Dom)\
**Post date:** [May 11, 2025, 8:07am UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/10 "2025-05-11T08:07:49Z")

</div>

hey @tonykipkemboi  
I have crewai version: 0.118.0 but the error is occuring. Same goes for this setup:  
crewai-0.119.0 litellm-1.68.0 openai-1.75.0

---

<div class="post-metadata">

**Author:** ![Matthew](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Matthew](https://community.crewai.com/u/Matthew)\
**Post date:** [May 13, 2025, 2:32pm UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/11 "2025-05-13T14:32:49Z")

</div>

5.12.2025 - litellm was just updated to version 1.69.2  
Is this update we have been waiting for?

---

<div class="post-metadata">

**Author:** ![sodoherty](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/sodoherty/32/2431_2.png) [@sodoherty](https://community.crewai.com/u/sodoherty)\
**Post date:** [May 13, 2025, 2:52pm UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/12 "2025-05-13T14:52:20Z")

</div>

I’m still getting the same error. Hot fixing the factory file worked until a proper fix.

---

<div class="post-metadata">

**Author:** ![rocketbro](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/rocketbro/32/3596_2.png) [@rocketbro](https://community.crewai.com/u/rocketbro)\
**Post date:** [May 14, 2025, 1:41pm UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/13 "2025-05-14T13:41:01Z")

</div>

Thank you! This worked for me too. Easy enough edit, I’ll just keep doing this with each upgrade til they fix it on their end

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex025/uploads/crewai/original/1X/ecda97e72f77c7100e0a761444b1c991925cc789.png) [@system](https://community.crewai.com/u/system)\
**Post date:** [May 17, 2025, 1:18pm UTC](https://community.crewai.com/t/list-index-out-of-range-msg-i/5612/14 "2025-05-17T13:18:47Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
