Skip to content

The agent that grows with you

fix(clarify): drop maxLength from the choices schema so llama.cpp can parse the grammar (#131286)

Charan Rathorecf6dca8d68e5
diff --git a/tests/tools/test_schema_sanitizer.py b/tests/tools/test_schema_sanitizer.py
index 8c8df995b89..982e10c231c 100644
--- a/tests/tools/test_schema_sanitizer.py
+++ b/tests/tools/test_schema_sanitizer.py
@@ -591,3 +591,42 @@ def test_builtin_tool_without_required_gets_empty_required_list():
"properties": {"opts": {"type": "object", "properties": {"k": {"type": "string"}}}},
})])[0]["function"]["parameters"]
assert nested["properties"]["opts"]["required"] == []
+
+
+# ---------------------------------------------------------------------------
+# #131278: llama.cpp's json-schema-to-grammar rejects bounded repetition >= 2000
+# ---------------------------------------------------------------------------
+
+
+def _walk_schema(node):
+ if isinstance(node, dict):
+ yield node
+ for v in node.values():
+ yield from _walk_schema(v)
+ elif isinstance(node, list):
+ for v in node:
+ yield from _walk_schema(v)
+
+
+def test_clarify_schema_has_no_unbounded_repetition_keyword():
+ """The clarify schema must not carry a length bound llama.cpp's grammar converter rejects."""
+ from tools.clarify_tool import CLARIFY_SCHEMA
+ for node in _walk_schema(CLARIFY_SCHEMA["parameters"]):
+ for key in ("maxLength", "minLength"):
+ assert node.get(key, 0) < 2000, f"{key}={node[key]} breaks llama.cpp grammar parsing"
+
+
+def test_registered_tool_schemas_stay_inside_llama_cpp_repetition_limit():
+ """No built-in tool may ship a length/count bound of 2000+ (llama.cpp rejects the whole request)."""
+ import model_tools # noqa: F401 — registers built-in tools
+ from tools.registry import registry
+ offenders = []
+ for name in registry.get_all_tool_names():
+ entry = registry.get_entry(name)
+ schema = getattr(entry, "schema", None) or {}
+ for node in _walk_schema(schema.get("parameters", {})):
+ for key in ("maxLength", "minLength", "maxItems", "minItems"):
+ val = node.get(key)
+ if isinstance(val, int) and val >= 2000:
+ offenders.append((name, key, val))
+ assert not offenders, offenders
diff --git a/tools/clarify_tool.py b/tools/clarify_tool.py
index b47fb048c38..b2c0f6f766f 100644
--- a/tools/clarify_tool.py
+++ b/tools/clarify_tool.py
@@ -169,7 +169,7 @@ CLARIFY_SCHEMA = {
"question": {"type": "string"},
"choices": {
"type": "array",
- "items": {"type": "string", "maxLength": MAX_CHOICE_CHARS},
+ "items": {"type": "string"}, # no maxLength: llama.cpp's grammar converter rejects >=2000 (#131278); the limit is enforced above
"maxItems": MAX_CHOICES,
},
"multi_select": {"type": "boolean"},