[GH-ISSUE #8003] Allow for forcing an order of properties in structured JSON response #30880

Closed
opened 2026-04-22 10:50:59 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @scd31 on GitHub (Dec 9, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/8003

When having an LLM respond with JSON I often do something along the lines of {reasoning: "...", actual_property_i_care_about: "..."}. The idea is that the reasoning property isn't used on my end but gives the LLM the ability to think first, like with CoT. Of course, this requires the LLM to populate the reasoning term before the other terms.

With the new structured JSON response it would be nice if there were a way to enforce this. Even telling the LLM to put the elements in a specific order is ignored.

Originally created by @scd31 on GitHub (Dec 9, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/8003 When having an LLM respond with JSON I often do something along the lines of `{reasoning: "...", actual_property_i_care_about: "..."}`. The idea is that the `reasoning` property isn't used on my end but gives the LLM the ability to think first, like with CoT. Of course, this requires the LLM to populate the `reasoning` term before the other terms. With the new structured JSON response it would be nice if there were a way to enforce this. Even telling the LLM to put the elements in a specific order is ignored.
GiteaMirror added the feature request label 2026-04-22 10:50:59 -05:00
Author
Owner

@scd31 commented on GitHub (Dec 9, 2024):

I did some digging and it looks like this will require a change to llama.cpp as well as Ollama (alternatively, we could just move the json_schema_to_grammar.cpp over to Ollama and modify it there, but it would be nice to backport the improvement)

As a side note it seems like the fields are ordered alphabetically, which is a workaround at least

<!-- gh-comment-id:2526654224 --> @scd31 commented on GitHub (Dec 9, 2024): I did some digging and it looks like this will require a change to llama.cpp as well as Ollama (alternatively, we could just move the `json_schema_to_grammar.cpp` over to Ollama and modify it there, but it would be nice to backport the improvement) As a side note it seems like the fields are ordered alphabetically, which is a workaround at least
Author
Owner

@rick-github commented on GitHub (Dec 9, 2024):

#7978

<!-- gh-comment-id:2526670483 --> @rick-github commented on GitHub (Dec 9, 2024): #7978
Author
Owner

@scd31 commented on GitHub (Dec 9, 2024):

Thanks (:

<!-- gh-comment-id:2527733702 --> @scd31 commented on GitHub (Dec 9, 2024): Thanks (:
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#30880