private String addPrimitive(String name, BuiltinRule builtinRule) {
        var rule = addRule(name, builtinRule.content);

        for (var dep : builtinRule.dependencies) {
            var depRule = PRIMITIVE_RULES.containsKey(dep) ? PRIMITIVE_RULES.get(dep) : FORMATTED_STRING_RULES.get(dep);

            if (depRule == null) {
                throw new IllegalArgumentException("Rule " + dep + " not known");
            }

            if (!rules.containsKey(dep)) {
                addPrimitive(dep, depRule);
            }
        }

        return rule;
    }
Converts a JSON Schema to a GBNF grammar to be used for structured output with llama.cpp.
It is a port of Python implementation from llama.cpp repository.
Current implementation doesn't support regex patterns, resolving $ref or fetching schemas from URLs.
The plan is to replace this with C++ implementation from llama.cpp though JNI.
model-integration/src/main/java/ai/vespa/llm/clients/JsonSchemaToGrammar.java