Skip to content

server: fix json_schema response_format handling#4

Merged
superbarne merged 2 commits intomasterfrom
copilot/merge-llama-cpp-pr-18963
Mar 15, 2026
Merged

server: fix json_schema response_format handling#4
superbarne merged 2 commits intomasterfrom
copilot/merge-llama-cpp-pr-18963

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 15, 2026

Make sure to read the contributing guidelines before submitting a PR

Merges upstream ggml-org/llama.cpp#18963.

When response_format.type is "json_schema" but json_schema.schema is missing, the server silently falls back to an empty schema {} which matches any JSON — effectively no constraint at all.

Changes:

  • tools/server/server-common.cpp: Validate that json_schema.schema is present; throw if missing. Update the invalid-type error message to list "json_schema" as a valid option.
  • tools/server/tests/unit/test_chat_completion.py: Add test cases for OpenAI-style json_schema with extra fields (name, strict), missing schema field (expect 400), and error message content assertions.
// Before: silently accepts, produces unconstrained JSON
{"type": "json_schema", "json_schema": {"name": "test"}}

// After: returns 400 with clear error
// "response_format type \"json_schema\" requires \"json_schema.schema\" to be set"

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add validation that json_schema.schema is present when using response_format.type: "json_schema"
- Update error message for invalid response_format types to include "json_schema"
- Add test cases for json_schema validation and error messages

Co-authored-by: superbarne <1502820+superbarne@users.noreply.github.com>
Copilot AI changed the title [WIP] Merge pull request #18963 from ggml-org/llama.cpp server: fix json_schema response_format handling Mar 15, 2026
Copilot AI requested a review from superbarne March 15, 2026 20:31
@superbarne superbarne marked this pull request as ready for review March 15, 2026 20:35
@superbarne superbarne merged commit a71a627 into master Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants