[GH-ISSUE #4018] API truncates parentheses before stop token #2493

Closed
opened 2026-04-12 12:49:17 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @IgorAlexey on GitHub (Apr 29, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/4018

What is the issue?

The generate API is truncating closing parentheses when they appear before a stop token at seemingly random occasions. This issue is reproducible across all models I've tested (Phi3, All llama3 versions, WizardLM2) so it looks like it's an API limitation?

sample text

Everyone uses `:)` at the end of their messages
|User|Message|
|-|-|
|User|Hello there! :)|
|UserB|
curl http://localhost:11434/api/generate -d '{"model": "llama3:instruct", "prompt": "Everyone uses `:)` at the end of their messages\\n|User|Message|\\n|-|-|\\n|User|Hello there! :)|\\n|UserB|", "raw": true, "stream": false, "options": {"stop": ["|"]}}'

P.S. If you don't see it the first time, run the command a couple times more and it might happen

Expected: The response should include the closing parentheses in the generated text, like so: ... :)
Actual: The response truncates the closing parentheses, resulting in ... :

This doesn't happen if the token that follows the ) isn't a stop token, but if it is, then it might take the ) with it.
It also happens with quotes and <>

Linux/Nvidia/Intel
Ollama 0.1.32

Originally created by @IgorAlexey on GitHub (Apr 29, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/4018 ### What is the issue? The generate API is truncating closing parentheses when they appear before a stop token at seemingly random occasions. This issue is reproducible across all models I've tested (Phi3, All llama3 versions, WizardLM2) so it looks like it's an API limitation? sample text ``` Everyone uses `:)` at the end of their messages |User|Message| |-|-| |User|Hello there! :)| |UserB| ``` ```bash curl http://localhost:11434/api/generate -d '{"model": "llama3:instruct", "prompt": "Everyone uses `:)` at the end of their messages\\n|User|Message|\\n|-|-|\\n|User|Hello there! :)|\\n|UserB|", "raw": true, "stream": false, "options": {"stop": ["|"]}}' ``` _P.S. If you don't see it the first time, run the command a couple times more and it might happen_ **Expected**: The response should include the closing parentheses in the generated text, like so: `... :)` **Actual**: The response truncates the closing parentheses, resulting in `... :` This doesn't happen if the token that follows the `)` isn't a stop token, but if it is, then it might take the `)` with it. It also happens with quotes and <> **Linux/Nvidia/Intel** Ollama **0.1.32**
GiteaMirror added the bug label 2026-04-12 12:49:17 -05:00
Author
Owner

@pdevine commented on GitHub (Jul 17, 2024):

@IgorAlexey Sorry for the slow reply. Your issue ended up getting buried in other issues :-D

In your examples you're using raw mode, but you're not creating the correct template around your prompt, so you're going to get some random results. You can get the template for any model by running ollama show --template <model>. In your example you would need to do something like:

<|start_header_id|>system<|end_header_id|>

Fill out the table with a :) at the end of every entry<|eot_id|><|start_header_id|>user<|end_header_id|>

|User|Message|\\n|-|-|\\n|User|Hello there! :)|\\n|UserB|<|eot_id|><|start_header_id|>assistant<|end_header_id|>

Watch out for the stop parameter that you set as well. I'm going to go ahead and close the issue since it seems to be working as expected.

<!-- gh-comment-id:2232076877 --> @pdevine commented on GitHub (Jul 17, 2024): @IgorAlexey Sorry for the slow reply. Your issue ended up getting buried in other issues :-D In your examples you're using `raw` mode, but you're not creating the correct template around your prompt, so you're going to get some random results. You can get the template for any model by running `ollama show --template <model>`. In your example you would need to do something like: ``` <|start_header_id|>system<|end_header_id|> Fill out the table with a :) at the end of every entry<|eot_id|><|start_header_id|>user<|end_header_id|> |User|Message|\\n|-|-|\\n|User|Hello there! :)|\\n|UserB|<|eot_id|><|start_header_id|>assistant<|end_header_id|> ``` Watch out for the stop parameter that you set as well. I'm going to go ahead and close the issue since it seems to be working as expected.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#2493