[GH-ISSUE #8392] Empty 'assistant' message #31148

Closed
opened 2026-04-22 11:20:15 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @pulinagrawal on GitHub (Jan 12, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/8392

What is the issue?

with the following python code

>>> import ollama
>>> my = {
...   "model": "llama3.2",
...   "options": {
...     "temperature": 0
...   },
...   "messages": [{"role": "system", "content": "You are a DnD Dungeon Master. Say something in your first message to the user."}
...   ],
...   "tools": [
...       {
...         "type": "function",
...         "function": {
...           "name": "roll_for_action",
...           "description": "Checks a dice roll for a skill with a given difficulty class",
...           "parameters": {
...               "type": "object",
...               "properties": {"n_dice": {"type": "integer"},
...                              "sides": {"type": "integer"},
...                              "skill": {"type": "string"},
...                              "dc": {"type": "integer"},
...                              "player": {"type": "string"}
...                             }
...           }
...         }
...       }]
... }
>>> response = ollama.chat(**my)
>>> print(response)
model='llama3.2' created_at='2025-01-12T06:38:51.757532Z' done=True done_reason='stop' total_duration=1349066625 load_duration=16419958 prompt_eval_count=66 prompt_eval_duration=1330000000 eval_count=1 eval_duration=1000000 message=Message(role='assistant', content='', images=None, tool_calls=None)

The response content is empty.

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.5.4

Originally created by @pulinagrawal on GitHub (Jan 12, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/8392 ### What is the issue? with the following python code ``` >>> import ollama >>> my = { ... "model": "llama3.2", ... "options": { ... "temperature": 0 ... }, ... "messages": [{"role": "system", "content": "You are a DnD Dungeon Master. Say something in your first message to the user."} ... ], ... "tools": [ ... { ... "type": "function", ... "function": { ... "name": "roll_for_action", ... "description": "Checks a dice roll for a skill with a given difficulty class", ... "parameters": { ... "type": "object", ... "properties": {"n_dice": {"type": "integer"}, ... "sides": {"type": "integer"}, ... "skill": {"type": "string"}, ... "dc": {"type": "integer"}, ... "player": {"type": "string"} ... } ... } ... } ... }] ... } >>> response = ollama.chat(**my) >>> print(response) model='llama3.2' created_at='2025-01-12T06:38:51.757532Z' done=True done_reason='stop' total_duration=1349066625 load_duration=16419958 prompt_eval_count=66 prompt_eval_duration=1330000000 eval_count=1 eval_duration=1000000 message=Message(role='assistant', content='', images=None, tool_calls=None) ``` The response content is empty. ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.5.4
GiteaMirror added the bug label 2026-04-22 11:20:15 -05:00
Author
Owner

@rick-github commented on GitHub (Jan 12, 2025):

The system message is generally used for setting the tone, supplying tools, etc and not direct instruction. LLMs are trained to perform generations from a user or assistant message, since none is supplied, the LLM has no response.

<!-- gh-comment-id:2585618786 --> @rick-github commented on GitHub (Jan 12, 2025): The system message is generally used for setting the tone, supplying tools, etc and not direct instruction. LLMs are trained to perform generations from a user or assistant message, since none is supplied, the LLM has no response.
Author
Owner

@pulinagrawal commented on GitHub (Jan 12, 2025):

That doesn't make sense. They are not trained to provide a welcome greeting message? I will be surprised if that is how they are created. I checked for a similar message with only a system prompt to ChatGPT. It produces an assistant message.

Anyway thanks for your response @rick-github.

By the way I was able to fix this issue by changing the template in Modelfile like so:

{{- end }}{{ if $last }}<|start_header_id|>assistant<|end_header_id|>

{{ end }}
{{- else if eq .Role "system" }} <|start_header_id|>assistant<|end_header_id|>

{{- else if eq .Role "assistant" }}<|start_header_id|>assistant<|end_header_id|>

I added {{- else if eq .Role "system" }} <|start_header_id|>assistant<|end_header_id|> on line 35.

<!-- gh-comment-id:2585636489 --> @pulinagrawal commented on GitHub (Jan 12, 2025): That doesn't make sense. They are not trained to provide a welcome greeting message? I will be surprised if that is how they are created. I checked for a similar message with only a system prompt to ChatGPT. It produces an assistant message. Anyway thanks for your response @rick-github. By the way I was able to fix this issue by changing the template in Modelfile like so: ``` {{- end }}{{ if $last }}<|start_header_id|>assistant<|end_header_id|> {{ end }} {{- else if eq .Role "system" }} <|start_header_id|>assistant<|end_header_id|> {{- else if eq .Role "assistant" }}<|start_header_id|>assistant<|end_header_id|> ``` I added ```{{- else if eq .Role "system" }} <|start_header_id|>assistant<|end_header_id|>``` on line 35.
Author
Owner

@rick-github commented on GitHub (Jan 12, 2025):

Modifying the template is not necessary, adding a blank assistant message to your prompt is enough.

<!-- gh-comment-id:2585645388 --> @rick-github commented on GitHub (Jan 12, 2025): Modifying the template is not necessary, adding a blank assistant message to your prompt is enough.
Author
Owner

@pulinagrawal commented on GitHub (Jan 12, 2025):

Thanks @rick-github that is a better solution.

close #8392

<!-- gh-comment-id:2585795163 --> @pulinagrawal commented on GitHub (Jan 12, 2025): Thanks @rick-github that is a better solution. close #8392
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#31148