[PR #8002] [MERGED] llama: preserve field order in user-defined JSON schemas #43833

Closed
opened 2026-04-24 23:24:48 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/8002
Author: @bmizerany
Created: 12/9/2024
Status: Merged
Merged: 12/11/2024
Merged by: @bmizerany

Base: mainHead: bmizerany/issue7978


📝 Commits (1)

  • 17baf5f llama: preserve field order in user-defined JSON schemas

📊 Changes

5 files changed (+104 additions, -114 deletions)

View changed files

llama/grammar_test.go (+80 -0)
📝 llama/llama.go (+9 -23)
📝 llama/llama_test.go (+0 -69)
📝 llm/server.go (+13 -16)
📝 openai/openai.go (+2 -6)

📄 Description

llama: preserve field order in user-defined JSON schemas

Previously we decoded and re-encoded JSON schemas during validation,
which served no purpose since json.RawMessage already validates JSON
syntax. Worse, the re-encoding lost field ordering from the original
schema, which affects inference quality during step-by-step reasoning.

While fixing this ordering issue by using json.RawMessage directly,
testing revealed that schema_to_grammar (from llama.cpp) also fails to
preserve field order during grammar generation. This appears to be the
root cause of inference degradation.

This change prevents us from mangling the user's original schema order,
but we still need to address the ordering issue in schema_to_grammar.
That will be a separate change.

Updates #7978


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/8002 **Author:** [@bmizerany](https://github.com/bmizerany) **Created:** 12/9/2024 **Status:** ✅ Merged **Merged:** 12/11/2024 **Merged by:** [@bmizerany](https://github.com/bmizerany) **Base:** `main` ← **Head:** `bmizerany/issue7978` --- ### 📝 Commits (1) - [`17baf5f`](https://github.com/ollama/ollama/commit/17baf5fbb046187fbe84a20639f46f0b3ac7f7dd) llama: preserve field order in user-defined JSON schemas ### 📊 Changes **5 files changed** (+104 additions, -114 deletions) <details> <summary>View changed files</summary> ➕ `llama/grammar_test.go` (+80 -0) 📝 `llama/llama.go` (+9 -23) 📝 `llama/llama_test.go` (+0 -69) 📝 `llm/server.go` (+13 -16) 📝 `openai/openai.go` (+2 -6) </details> ### 📄 Description llama: preserve field order in user-defined JSON schemas Previously we decoded and re-encoded JSON schemas during validation, which served no purpose since json.RawMessage already validates JSON syntax. Worse, the re-encoding lost field ordering from the original schema, which affects inference quality during step-by-step reasoning. While fixing this ordering issue by using json.RawMessage directly, testing revealed that schema_to_grammar (from llama.cpp) also fails to preserve field order during grammar generation. This appears to be the root cause of inference degradation. This change prevents us from mangling the user's original schema order, but we still need to address the ordering issue in schema_to_grammar. That will be a separate change. Updates #7978 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-24 23:24:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#43833