[GH-ISSUE #9276] Resolving ValueError: Unsupported Message Type Error in LangGraph and Ollama Integration #6047

Closed
opened 2026-04-12 17:22:47 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @nwheeler81 on GitHub (Feb 21, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/9276

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

Originally created by @nwheeler81 on GitHub (Feb 21, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/9276 ### 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 ```shell .../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
GiteaMirror added the bug label 2026-04-12 17:22:47 -05:00
Author
Owner

@rick-github commented on GitHub (Feb 21, 2025):

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
<!-- gh-comment-id:2674994927 --> @rick-github commented on GitHub (Feb 21, 2025): 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"]. ```python 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 ```
Author
Owner

@ENUMERA8OR commented on GitHub (Feb 26, 2025):

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.

<!-- gh-comment-id:2685742139 --> @ENUMERA8OR commented on GitHub (Feb 26, 2025): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#6047