Commit 61d456a23 for llama.cpp
commit 61d456a2326aba38cf63694bc38ec1f9f3f113f0
Author: Martin Emrich <6672718+MartinEmrich@users.noreply.github.com>
Date: Wed Nov 25 09:35:44 2026 +0100
common : accept boolean "value": true JSON schema (#32908)
* accept boolean "true" JSON schema
... as sent e.g. by "RAGFlow".
* revert over-eager tests
diff --git a/common/json-schema.cpp b/common/json-schema.cpp
index eb57a524a..ac69f6691 100644
--- a/common/json-schema.cpp
+++ b/common/json-schema.cpp
@@ -244,6 +244,12 @@ class common_chat_schema_builder {
}
common_chat_schema_ptr build_node_impl(const common_json & schema, const std::string & path) {
+ if (schema.is_boolean()) {
+ if (schema.get<bool>()) {
+ return std::make_unique<common_chat_schema_any>(); // true matches any value, like {}
+ }
+ fail(path, "false schema is not supported"); // false matches nothing, the grammar cannot express it
+ }
if (!schema.is_object()) {
fail(path, "schema must be an object");
}
diff --git a/tests/test-json-schema.cpp b/tests/test-json-schema.cpp
index fb8cee18b..4460badb8 100644
--- a/tests/test-json-schema.cpp
+++ b/tests/test-json-schema.cpp
@@ -48,6 +48,11 @@ static void test_any(testing & t) {
auto doc = parse(R"({"description": "x", "format": "email", "additionalProperties": true})");
root<common_chat_schema_any>(t, doc);
});
+
+ t.test("boolean true is any", [](testing & t) {
+ auto doc_prop = parse(R"({"properties": {"a": true}})");
+ as<common_chat_schema_any>(t, root<common_chat_schema_object>(t, doc_prop).properties[0].schema.get(), "a");
+ });
}
static void test_primitives(testing & t) {
@@ -449,6 +454,10 @@ static void test_errors(testing & t) {
assert_error(t, R"([])", "#: schema must be an object");
});
+ t.test("false schema", [](testing & t) {
+ assert_error(t, R"({"properties": {"a": false}})", "#/properties/a: false schema is not supported");
+ });
+
t.test("type", [](testing & t) {
assert_error(t, R"({"type": 5})", "#: type must be a string or an array of strings");
assert_error(t, R"({"type": []})", "#: type must not be empty");