ollama icon indicating copy to clipboard operation
ollama copied to clipboard

Resolving ValueError: Unsupported Message Type Error in LangGraph and Ollama Integration

Open nwheeler81 opened this issue 9 months ago • 2 comments

What is the issue?

Hi @dhiltgen I'm facing the issue ValueError: Received unsupported message type for Ollama with LangGraph and Ollama: langchain-ollama 0.2.3 ollama 0.4.7 langchain 0.3.18 langchain-core 0.3.35 langchain-ollama 0.2.3 langgraph 0.2.72

Relevant log output

.../python3.13/site-packages/langchain_community/chat_models/ollama.py:134, in ChatOllama._convert_messages_to_ollama_messages(self, messages)
    132     role = "system"
    133 else:
--> 134     raise ValueError("Received unsupported message type for Ollama.")
    136 content = ""
    137 images = []

ValueError: Received unsupported message type for Ollama.
During task with name 'assistant' and id 'a39a5c4c-bf89-473f-d767-cbd3b3d5c640'

OS

macOS

GPU

Nvidia, Apple

CPU

Apple

Ollama version

0.4.7

nwheeler81 avatar Feb 21 '25 15:02 nwheeler81

This would appear to be a problem with langgraph or your app. It's trying to send a message to ollama with a role that langgraph thinks is not supported by ollama, ie one of ["user", "assistant", "system"].

   121      def _convert_messages_to_ollama_messages(
   122          self, messages: List[BaseMessage]
   123      ) -> List[Dict[str, Union[str, List[str]]]]:
   124          ollama_messages: List = []
   125          for message in messages:
   126              role = ""
   127              if isinstance(message, HumanMessage):
   128                  role = "user"
   129              elif isinstance(message, AIMessage):
   130                  role = "assistant"
   131              elif isinstance(message, SystemMessage):
   132                  role = "system"
   133              else:
   134                  raise ValueError("Received unsupported message type for Ollama.")
   135

rick-github avatar Feb 21 '25 16:02 rick-github

You will need to statically pass the message structure that langchain expects. Create a new class with the help of chatgpt or claude & then try to pass that manually.

ENUMERA8OR avatar Feb 26 '25 17:02 ENUMERA8OR