[GH-ISSUE #11440] Incorrect llama-guard3 chat template for Agent output assessment #69612

Open
opened 2026-05-04 18:38:28 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @TomaszChrosniak on GitHub (Jul 16, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/11440

What is the issue?

Hi,
I'm not sure if these requests should be raised as bugs here, but I've been experimenting with llama-guard3 model on Ollama, and was surprised by some of the classification.
Upon inspection of the chat template, I noticed that it's not correct.
The last part of the template is only valid for user prompt classification, and the variant for model response classification is missing.

Template snippet as currently present:

Provide your safety assessment for ONLY THE LAST User message in the above conversation:
 - First line must read 'safe' or 'unsafe'.
 - If unsafe, a second line must include a comma-separated list of violated categories.

What it seems that it should be, based on the paper (Llama Guard arXiv 2312.06674) and templates used elsewhere (HuggingFace)

Provide your safety assessment for ONLY THE LAST {{ $role }} message in the above conversation:
- First line must read 'safe' or 'unsafe'.
- If unsafe, a second line must include a comma-separated list of violated categories.

Please let me know if I've made a mistake and/or should've posted elsewhere.

Cheers,

Relevant log output


OS

No response

GPU

No response

CPU

No response

Ollama version

No response

Originally created by @TomaszChrosniak on GitHub (Jul 16, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/11440 ### What is the issue? Hi, I'm not sure if these requests should be raised as bugs here, but I've been experimenting with `llama-guard3` model on Ollama, and was surprised by some of the classification. Upon inspection of the chat template, I noticed that it's not correct. The last part of the template is only valid for user prompt classification, and the variant for model response classification is missing. Template snippet as [currently present](https://ollama.com/library/llama-guard3:8b/blobs/cb5a7b24ae22): ``` Provide your safety assessment for ONLY THE LAST User message in the above conversation: - First line must read 'safe' or 'unsafe'. - If unsafe, a second line must include a comma-separated list of violated categories. ``` What it seems that it should be, based on the paper ([Llama Guard arXiv 2312.06674](https://arxiv.org/abs/2312.06674)) and templates used elsewhere ([HuggingFace](https://huggingface.co/meta-llama/Llama-Guard-3-8B/blob/main/tokenizer_config.json)) ``` Provide your safety assessment for ONLY THE LAST {{ $role }} message in the above conversation: - First line must read 'safe' or 'unsafe'. - If unsafe, a second line must include a comma-separated list of violated categories. ``` Please let me know if I've made a mistake and/or should've posted elsewhere. Cheers, ### Relevant log output ```shell ``` ### OS _No response_ ### GPU _No response_ ### CPU _No response_ ### Ollama version _No response_
GiteaMirror added the bug label 2026-05-04 18:38:28 -05:00
Author
Owner

@AngelAlita commented on GitHub (Dec 17, 2025):

+1, I’m seeing the same behavior and I agree the current chat template looks wrong for response classification.

<!-- gh-comment-id:3664243367 --> @AngelAlita commented on GitHub (Dec 17, 2025): +1, I’m seeing the same behavior and I agree the current chat template looks wrong for response classification.
Author
Owner

@aivf-harry commented on GitHub (Feb 26, 2026):

+1, same issue here.

While it's not an issue for classifying user input, it impacts significantly on classification agent responses/ output (~50% misclassification against our human annotation).

Unfortunately I'm unable to raise PR to fix this as this template isn't in the template folder. Can the team please prioritize this fix? Thank you so much!

<!-- gh-comment-id:3965115564 --> @aivf-harry commented on GitHub (Feb 26, 2026): +1, same issue here. While it's not an issue for classifying user input, it impacts significantly on classification agent responses/ output **(~50% misclassification against our human annotation)**. Unfortunately I'm unable to raise PR to fix this as this template isn't in the template folder. Can the team please prioritize this fix? Thank you so much!
Author
Owner

@aivf-xingyong commented on GitHub (Mar 26, 2026):

One workaround is to edit the chat template which is the "modelfile" using bash command.
ollama show <model_name> --modelfile > my_model.modelfile
Replace my_model.modelfile to reflect the changes stated above

Provide your safety assessment for ONLY THE LAST User message in the above conversation:
 - First line must read 'safe' or 'unsafe'.
 - If unsafe, a second line must include a comma-separated list of violated categories.

to

Provide your safety assessment for ONLY THE LAST {{ $role }} message in the above conversation:
- First line must read 'safe' or 'unsafe'.
- If unsafe, a second line must include a comma-separated list of violated categories.

Then update the modelfile in Ollama.
ollama create <model_name> -f my_model.modelfile

Now your llamaguard should be using the new chat template.

Alternatively, if you have your own template or pre-prompt, you can just replace the modelfile with an empty .modelfile.

<!-- gh-comment-id:4131663869 --> @aivf-xingyong commented on GitHub (Mar 26, 2026): One workaround is to edit the chat template which is the "_modelfile_" using bash command. `ollama show <model_name> --modelfile > my_model.modelfile` Replace my_model.modelfile to reflect the changes stated above ``` Provide your safety assessment for ONLY THE LAST User message in the above conversation: - First line must read 'safe' or 'unsafe'. - If unsafe, a second line must include a comma-separated list of violated categories. ``` to ``` Provide your safety assessment for ONLY THE LAST {{ $role }} message in the above conversation: - First line must read 'safe' or 'unsafe'. - If unsafe, a second line must include a comma-separated list of violated categories. ``` Then update the _modelfile_ in Ollama. `ollama create <model_name> -f my_model.modelfile` Now your llamaguard should be using the new chat template. Alternatively, if you have your own template or pre-prompt, you can just replace the _modelfile_ with an empty .modelfile.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#69612