private String addRule(String name, String content) {
        var finalName = INVALID_RULE_CHARS_RE.matcher(name).replaceAll("-");

        if (rules.containsKey(finalName) && !rules.get(finalName).equals(content)) {
            var index = 0;

            while (rules.containsKey(finalName + index) && !rules.get(finalName + index).equals(content)) {
                index += 1;
            }

            finalName = finalName + index;
        }

        rules.put(finalName, content);
        return finalName;
    }
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