public static String expandPrompt(String input, String promptTemplate, String jsonSchema) {
        if (promptTemplate != null) {
            var prompt = promptTemplate;

            if (prompt.contains("{input}")) {
                if (input != null) {
                    prompt = prompt.replace("{input}", input);
                } else {
                    throw new IllegalArgumentException("There no input to add to the prompt: %s"
                            .formatted(prompt));
                }
            }

            if (prompt.contains("{jsonSchema}")) {
                if (jsonSchema != null) {
                    prompt = prompt.replace("{jsonSchema}", jsonSchema);
                } else {
                    throw new IllegalArgumentException("There no JSON schema to add to the prompt: %s"
                            .formatted(prompt));
                }
            }

            return prompt;
        }

        if (input != null) {
            var prompt = input;

            if (prompt.contains("{jsonSchema}")) {
                if (jsonSchema != null) {
                    prompt = prompt.replace("{jsonSchema}", jsonSchema);
                } else {
                    throw new IllegalArgumentException("There no JSON schema to add to the prompt: %s"
                            .formatted(prompt));
                }
            }

            return prompt;
        }

        throw new IllegalArgumentException("Can't construct a prompt without a prompt template or an input text.");
    }
Utilities for working with language models.
 
 @author glebashnik
model-integration/src/main/java/ai/vespa/llm/generation/LanguageModelUtils.java