ollama._types.ResponseError: json: cannot unmarshal array into Go struct field .tools.function.parameters.properties.type of type string

from phi.agent import Agent
from phi.model.ollama import Ollama
from phi.tools.crawl4ai_tools import Crawl4aiTools

agent = Agent(
model=Ollama(id=“qwen2.5:7b”),
tools=[Crawl4aiTools(max_length=None)],
show_tool_calls=True
)
agent.print_response(“Tell me about https://github.com/phidatahq/phidata.”, markdown=True)

ollama._types.ResponseError: json: cannot unmarshal array into Go struct field .tools.function.parameters.properties.type of type string

Hey @zgli, the issue here is that we haven’t built function calling for Qwen on Ollama. Can you try llama3.1?

Thanks, but the bug is the same

model=Ollama(id=“llama3.2:latest”),

This seems to be an issue with the Crawl4ai tool rather than the model. I tested both the models against a few other tools and it’s working fine. Can you try using some other tool if it’s to test Ollama? Else you can try using other tools for web scraping like firecrawl

from phi.agent import Agent
from phi.model.ollama import Ollama
from phi.tools.firecrawl import FirecrawlTools

agent = Agent(
model=Ollama(id=“llama3.2:latest”),
tools=[FirecrawlTools(api_key=‘*****’,scrape=False, crawl=True)],
show_tool_calls=True
)
agent.print_response(“Tell me about https://github.com/phidatahq/phidata.”, markdown=True)


Traceback (most recent call last):
File “/Users/cindy/Documents/AI/jiaoxing/jiaoxing/admin/webstie.py”, line 11, in
agent.print_response(“Tell me about https://github.com/phidatahq/phidata.”, markdown=True)
File “/Users/cindy/Documents/AI/jiaoxing/jiaoxing/.venv/lib/python3.11/site-packages/phi/agent/agent.py”, line 2698, in print_response
run_response = self.run(message=message, messages=messages, stream=False, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/cindy/Documents/AI/jiaoxing/jiaoxing/.venv/lib/python3.11/site-packages/phi/agent/agent.py”, line 1884, in run
return next(resp)
^^^^^^^^^^
File “/Users/cindy/Documents/AI/jiaoxing/jiaoxing/.venv/lib/python3.11/site-packages/phi/agent/agent.py”, line 1660, in _run
model_response = self.model.response(messages=messages_for_model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/cindy/Documents/AI/jiaoxing/jiaoxing/.venv/lib/python3.11/site-packages/phi/model/ollama/chat.py”, line 423, in response
response: Mapping[str, Any] = self.invoke(messages=messages)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/cindy/Documents/AI/jiaoxing/jiaoxing/.venv/lib/python3.11/site-packages/phi/model/ollama/chat.py”, line 192, in invoke
return self.get_client().chat(
^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/cindy/Documents/AI/jiaoxing/jiaoxing/.venv/lib/python3.11/site-packages/ollama/_client.py”, line 236, in chat
return self._request_stream(
^^^^^^^^^^^^^^^^^^^^^
File “/Users/cindy/Documents/AI/jiaoxing/jiaoxing/.venv/lib/python3.11/site-packages/ollama/_client.py”, line 99, in _request_stream
return self._stream(*args, **kwargs) if stream else self._request(*args, **kwargs).json()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/cindy/Documents/AI/jiaoxing/jiaoxing/.venv/lib/python3.11/site-packages/ollama/_client.py”, line 75, in _request
raise ResponseError(e.response.text, e.response.status_code) from None
ollama._types.ResponseError: json: cannot unmarshal array into Go struct field .tools.function.parameters.properties.type of type string

Hey @zgli, give me some time to debug this issue. This seems to happen for ollama for multiple tools. I will get back to you with a fix for this

1 Like

any updates on the issue as i am getting the same error but for tools like DuckDuckGo() and YFinance. although these agents work alright when they are not in a team(i.e. when a single agent is run) but when in a team this error occurs:
ollama._types.ResponseError: json: cannot unmarshal array into Go struct field .tools.function.parameters.properties.type of type string

Hi @ansh363
Thank you for reaching out and using Phidata! I’ve tagged the relevant engineers to assist you with your query. We aim to respond within 24 hours.
If this is urgent, please feel free to let us know, and we’ll do our best to prioritize it.
Thanks for your patience!

Hi @Monali
I’m facing the same issue when I try to use ollama with CSV Tools.

It would be helpful if the team prioritizes it.

Thankyou

Hey @ansh363 and @Harry, the team is working on a fix and you should soon see a PR for this out.

1 Like

Hi @Hi @ manthanguptaa
I’m facing the same issue when I try to use ollama in team creation context.


hn_team = Agent(
    name="Hackernews Team",
    team=[hn_researcher, web_searcher, article_reader],
    model=Ollama(id="llama3.2"),
    instructions=[
        "First, search hackernews for what the user is asking about.",
        "Then, ask the article reader to read the links for the stories to get more information.",
        "Important: you must provide the article reader with the links to read.",
        "Then, ask the web searcher to search for each story to get more information.",
        "Finally, provide a thoughtful and engaging summary.",
    ],
    show_tool_calls=True,
    markdown=True,
)
hn_team.print_response("Write an article about the top 2 stories on hackernews", stream=True)

return error below:

ollama._types.ResponseError: json: cannot unmarshal array into Go struct field .tools.function.parameters.properties.type of type string

It would be helpful if the team prioritizes it.

Thankyou

Hi @vincevegafr
Thank you for reaching out and using Phidata! I’ve tagged the relevant engineers to assist you with your query. We aim to respond within 24 hours.
If this is urgent, please feel free to let us know, and we’ll do our best to prioritize it.
Thanks for your patience!

1 Like

Hey @vincevegafr @Harry @ansh363 @zgli, we have pushed an alternate class named OllamaTools. Please give it a try and let me know if it works for you
Here is a cookbook of Agent Team: phidata/cookbook/providers/ollama_tools/agent_team.py at main · phidatahq/phidata · GitHub

Hello @manthanguptaa

Many thanks for the update!
The update version works perfectly and solve my problem.
I added an additionnal line model=OllamaTools(id="llama3.1"), in declaration block agent_team to not refer to openai but to ollama.
Thank you again for your great job