[GH-ISSUE #2577] JSON mode should disallow trailing whitespace #63554

Closed
opened 2026-05-03 14:09:27 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @joliss on GitHub (Feb 18, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/2577

When using --format json, small models sometimes try to add more text after the object, resulting in infinite whitespace.

$ ollama run qwen:0.5b-chat-v1.5-q4_K_M 'Reply with only an example JSON object' --format json
{
  "name": "John",
  "age": 30,
  "city": "New York"
}








[whitespace continues indefinitely]

I think this could be easily fixed by disallowing trailing whitespace in JSON mode; that is, by forcing the assistant message to terminate immediately after the closing } of the top-level JSON object.

Originally created by @joliss on GitHub (Feb 18, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/2577 When using `--format json`, small models sometimes try to add more text after the object, resulting in infinite whitespace. ``` $ ollama run qwen:0.5b-chat-v1.5-q4_K_M 'Reply with only an example JSON object' --format json { "name": "John", "age": 30, "city": "New York" } [whitespace continues indefinitely] ``` I think this could be easily fixed by disallowing trailing whitespace in JSON mode; that is, by forcing the assistant message to terminate immediately after the closing `}` of the top-level JSON object.
GiteaMirror added the feature request label 2026-05-03 14:09:27 -05:00
Author
Owner

@ParthSareen commented on GitHub (Dec 5, 2024):

Would recommend trying out structured outputs! Json mode will eventually be deprecated

<!-- gh-comment-id:2518852744 --> @ParthSareen commented on GitHub (Dec 5, 2024): Would recommend trying out structured outputs! Json mode will eventually be deprecated
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#63554