Role of control returns an error. #262

Closed
opened 2026-02-15 16:29:19 -05:00 by yindo · 1 comment
Owner

Originally created by @sodohertyIBM on GitHub (Apr 16, 2025).

The granite3.2 model has a role of control and attribute of thinking option in chat.

https://ollama.com/library/granite3.2 (see end of page)

Sample code:

from ollama import Client

client = Client()
response = client.chat(
    model='granite3.2',
    messages=[
        {"role": "control", "content": "thinking"},
        {"role": "user", "content": "Name 5 Irish actors in a bullet list." }
    ]
).response

print(response)

This fails (stack below). If I use the same messages in a curl command the model works correctly.

Stack trace:

ValidationError                           Traceback (most recent call last)
Cell In[20], line 4
      1 from ollama import Client
      3 client = Client()
----> 4 response = client.chat(
      5     model='granite3.2',
      6     messages=[
      7         {"role": "control", "content": "thinking"},
      8         {"role": "user", "content": "Name 5 Irish actors in a bullet list." }
      9     ]
     10 ).response
     12 print(response)

File ~/PycharmProjects/Granite3.2-vision_test/.venv/lib/python3.11/site-packages/ollama/_client.py:339, in Client.chat(self, model, messages, tools, stream, format, options, keep_alive)
    289 def chat(
    290   self,
    291   model: str = '',
   (...)    298   keep_alive: Optional[Union[float, str]] = None,
    299 ) -> Union[ChatResponse, Iterator[ChatResponse]]:
    300   """
    301   Create a chat response using the requested model.
    302 
   (...)    331   Returns `ChatResponse` if `stream` is `False`, otherwise returns a `ChatResponse` generator.
    332   """
    333   return self._request(
    334     ChatResponse,
    335     'POST',
    336     '/api/chat',
    337     json=ChatRequest(
    338       model=model,
--> 339       messages=[message for message in _copy_messages(messages)],
    340       tools=[tool for tool in _copy_tools(tools)],
    341       stream=stream,
    342       format=format,
    343       options=options,
    344       keep_alive=keep_alive,
    345     ).model_dump(exclude_none=True),
    346     stream=stream,
    347   )

File ~/PycharmProjects/Granite3.2-vision_test/.venv/lib/python3.11/site-packages/ollama/_client.py:339, in <listcomp>(.0)
    289 def chat(
    290   self,
    291   model: str = '',
   (...)    298   keep_alive: Optional[Union[float, str]] = None,
    299 ) -> Union[ChatResponse, Iterator[ChatResponse]]:
    300   """
    301   Create a chat response using the requested model.
    302 
   (...)    331   Returns `ChatResponse` if `stream` is `False`, otherwise returns a `ChatResponse` generator.
    332   """
    333   return self._request(
    334     ChatResponse,
    335     'POST',
    336     '/api/chat',
    337     json=ChatRequest(
    338       model=model,
--> 339       messages=[message for message in _copy_messages(messages)],
    340       tools=[tool for tool in _copy_tools(tools)],
    341       stream=stream,
    342       format=format,
    343       options=options,
    344       keep_alive=keep_alive,
    345     ).model_dump(exclude_none=True),
    346     stream=stream,
    347   )

File ~/PycharmProjects/Granite3.2-vision_test/.venv/lib/python3.11/site-packages/ollama/_client.py:1135, in _copy_messages(messages)
   1133 def _copy_messages(messages: Optional[Sequence[Union[Mapping[str, Any], Message]]]) -> Iterator[Message]:
   1134   for message in messages or []:
-> 1135     yield Message.model_validate(
   1136       {k: [image for image in _copy_images(v)] if k == 'images' else v for k, v in dict(message).items() if v},
   1137     )

File ~/PycharmProjects/Granite3.2-vision_test/.venv/lib/python3.11/site-packages/pydantic/main.py:627, in BaseModel.model_validate(cls, obj, strict, from_attributes, context)
    625 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    626 __tracebackhide__ = True
--> 627 return cls.__pydantic_validator__.validate_python(
    628     obj, strict=strict, from_attributes=from_attributes, context=context
    629 )

ValidationError: 1 validation error for Message
role
  Input should be 'user', 'assistant', 'system' or 'tool' [type=literal_error, input_value='control', input_type=str]
    For further information visit https://errors.pydantic.dev/2.10/v/literal_error
Originally created by @sodohertyIBM on GitHub (Apr 16, 2025). The granite3.2 model has a role of `control` and attribute of `thinking` option in chat. https://ollama.com/library/granite3.2 (see end of page) Sample code: ``` from ollama import Client client = Client() response = client.chat( model='granite3.2', messages=[ {"role": "control", "content": "thinking"}, {"role": "user", "content": "Name 5 Irish actors in a bullet list." } ] ).response print(response) ``` This fails (stack below). If I use the same messages in a curl command the model works correctly. Stack trace: ``` ValidationError Traceback (most recent call last) Cell In[20], line 4 1 from ollama import Client 3 client = Client() ----> 4 response = client.chat( 5 model='granite3.2', 6 messages=[ 7 {"role": "control", "content": "thinking"}, 8 {"role": "user", "content": "Name 5 Irish actors in a bullet list." } 9 ] 10 ).response 12 print(response) File ~/PycharmProjects/Granite3.2-vision_test/.venv/lib/python3.11/site-packages/ollama/_client.py:339, in Client.chat(self, model, messages, tools, stream, format, options, keep_alive) 289 def chat( 290 self, 291 model: str = '', (...) 298 keep_alive: Optional[Union[float, str]] = None, 299 ) -> Union[ChatResponse, Iterator[ChatResponse]]: 300 """ 301 Create a chat response using the requested model. 302 (...) 331 Returns `ChatResponse` if `stream` is `False`, otherwise returns a `ChatResponse` generator. 332 """ 333 return self._request( 334 ChatResponse, 335 'POST', 336 '/api/chat', 337 json=ChatRequest( 338 model=model, --> 339 messages=[message for message in _copy_messages(messages)], 340 tools=[tool for tool in _copy_tools(tools)], 341 stream=stream, 342 format=format, 343 options=options, 344 keep_alive=keep_alive, 345 ).model_dump(exclude_none=True), 346 stream=stream, 347 ) File ~/PycharmProjects/Granite3.2-vision_test/.venv/lib/python3.11/site-packages/ollama/_client.py:339, in <listcomp>(.0) 289 def chat( 290 self, 291 model: str = '', (...) 298 keep_alive: Optional[Union[float, str]] = None, 299 ) -> Union[ChatResponse, Iterator[ChatResponse]]: 300 """ 301 Create a chat response using the requested model. 302 (...) 331 Returns `ChatResponse` if `stream` is `False`, otherwise returns a `ChatResponse` generator. 332 """ 333 return self._request( 334 ChatResponse, 335 'POST', 336 '/api/chat', 337 json=ChatRequest( 338 model=model, --> 339 messages=[message for message in _copy_messages(messages)], 340 tools=[tool for tool in _copy_tools(tools)], 341 stream=stream, 342 format=format, 343 options=options, 344 keep_alive=keep_alive, 345 ).model_dump(exclude_none=True), 346 stream=stream, 347 ) File ~/PycharmProjects/Granite3.2-vision_test/.venv/lib/python3.11/site-packages/ollama/_client.py:1135, in _copy_messages(messages) 1133 def _copy_messages(messages: Optional[Sequence[Union[Mapping[str, Any], Message]]]) -> Iterator[Message]: 1134 for message in messages or []: -> 1135 yield Message.model_validate( 1136 {k: [image for image in _copy_images(v)] if k == 'images' else v for k, v in dict(message).items() if v}, 1137 ) File ~/PycharmProjects/Granite3.2-vision_test/.venv/lib/python3.11/site-packages/pydantic/main.py:627, in BaseModel.model_validate(cls, obj, strict, from_attributes, context) 625 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks 626 __tracebackhide__ = True --> 627 return cls.__pydantic_validator__.validate_python( 628 obj, strict=strict, from_attributes=from_attributes, context=context 629 ) ValidationError: 1 validation error for Message role Input should be 'user', 'assistant', 'system' or 'tool' [type=literal_error, input_value='control', input_type=str] For further information visit https://errors.pydantic.dev/2.10/v/literal_error ```
yindo closed this issue 2026-02-15 16:29:20 -05:00
Author
Owner

@ParthSareen commented on GitHub (Apr 16, 2025):

Just released! Sorry about that! https://github.com/ollama/ollama-python/releases/tag/v0.4.8

@ParthSareen commented on GitHub (Apr 16, 2025): Just released! Sorry about that! https://github.com/ollama/ollama-python/releases/tag/v0.4.8
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#262