diff --git a/core/deployment/src/test/java/io/quarkiverse/langchain4j/test/guardrails/InputGuardrailPromptTemplateTest.java b/core/deployment/src/test/java/io/quarkiverse/langchain4j/test/guardrails/InputGuardrailPromptTemplateTest.java index 92ff09b53..921d77b0c 100644 --- a/core/deployment/src/test/java/io/quarkiverse/langchain4j/test/guardrails/InputGuardrailPromptTemplateTest.java +++ b/core/deployment/src/test/java/io/quarkiverse/langchain4j/test/guardrails/InputGuardrailPromptTemplateTest.java @@ -142,7 +142,7 @@ void shouldWorkWithMemoryIdAndOneItemFromList() { void shouldWorkWithNoUserMessage() { // UserMessage annotation is not provided, then no user message template should be available aiService.saySomething("Is this a parameter or a prompt?"); - assertThat(guardrailValidation.spyUserMessageTemplate()).isNull(); + assertThat(guardrailValidation.spyUserMessageTemplate()).isEmpty(); assertThat(guardrailValidation.spyVariables()).isEmpty(); } diff --git a/core/deployment/src/test/java/io/quarkiverse/langchain4j/test/guardrails/OutputGuardrailPromptTemplateTest.java b/core/deployment/src/test/java/io/quarkiverse/langchain4j/test/guardrails/OutputGuardrailPromptTemplateTest.java index 3c170f17b..1bf2ea7d4 100644 --- a/core/deployment/src/test/java/io/quarkiverse/langchain4j/test/guardrails/OutputGuardrailPromptTemplateTest.java +++ b/core/deployment/src/test/java/io/quarkiverse/langchain4j/test/guardrails/OutputGuardrailPromptTemplateTest.java @@ -139,7 +139,7 @@ void shouldWorkWithMemoryIdAndOneItemFromList() { void shouldWorkWithNoUserMessage() { // UserMessage annotation is not provided, then no user message template should be available aiService.saySomething("Is this a parameter or a prompt?"); - assertThat(guardrailValidation.spyUserMessageTemplate()).isNull(); + assertThat(guardrailValidation.spyUserMessageTemplate()).isEmpty(); assertThat(guardrailValidation.spyVariables()).isEmpty(); } diff --git a/core/runtime/src/main/java/io/quarkiverse/langchain4j/guardrails/InputGuardrailParams.java b/core/runtime/src/main/java/io/quarkiverse/langchain4j/guardrails/InputGuardrailParams.java index b27371263..1900d27b1 100644 --- a/core/runtime/src/main/java/io/quarkiverse/langchain4j/guardrails/InputGuardrailParams.java +++ b/core/runtime/src/main/java/io/quarkiverse/langchain4j/guardrails/InputGuardrailParams.java @@ -12,8 +12,8 @@ * @param userMessage the user message, cannot be {@code null} * @param memory the memory, can be {@code null} or empty * @param augmentationResult the augmentation result, can be {@code null} - * @param userMessageTemplate the user message template, can be {@code null} when @UserMessage is not provided. - * @param variables the variable to be used with userMessageTemplate, can be {@code null} or empty + * @param userMessageTemplate the user message template, cannot be {@code null} + * @param variables the variable to be used with userMessageTemplate, cannot be {@code null} */ public record InputGuardrailParams(UserMessage userMessage, ChatMemory memory, AugmentationResult augmentationResult, String userMessageTemplate, diff --git a/core/runtime/src/main/java/io/quarkiverse/langchain4j/guardrails/OutputGuardrailParams.java b/core/runtime/src/main/java/io/quarkiverse/langchain4j/guardrails/OutputGuardrailParams.java index 3bc39f2cd..0162c5f5a 100644 --- a/core/runtime/src/main/java/io/quarkiverse/langchain4j/guardrails/OutputGuardrailParams.java +++ b/core/runtime/src/main/java/io/quarkiverse/langchain4j/guardrails/OutputGuardrailParams.java @@ -12,8 +12,8 @@ * @param responseFromLLM the response from the LLM * @param memory the memory, can be {@code null} or empty * @param augmentationResult the augmentation result, can be {@code null} - * @param userMessageTemplate the user message template, can be {@code null} when @UserMessage is not provided. - * @param variables the variable to be used with userMessageTemplate, can be {@code null} or empty + * @param userMessageTemplate the user message template, cannot be {@code null} + * @param variables the variable to be used with userMessageTemplate, cannot be {@code null} */ public record OutputGuardrailParams(AiMessage responseFromLLM, ChatMemory memory, AugmentationResult augmentationResult, String userMessageTemplate, diff --git a/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/aiservice/AiServiceMethodCreateInfo.java b/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/aiservice/AiServiceMethodCreateInfo.java index dc095ec2b..e1c26af15 100644 --- a/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/aiservice/AiServiceMethodCreateInfo.java +++ b/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/aiservice/AiServiceMethodCreateInfo.java @@ -1,5 +1,7 @@ package io.quarkiverse.langchain4j.runtime.aiservice; +import static org.apache.commons.lang3.StringUtils.EMPTY; + import java.lang.reflect.Type; import java.util.List; import java.util.Map; @@ -197,7 +199,7 @@ public String getUserMessageTemplate() { Optional userMessageTemplateOpt = this.getUserMessageInfo().template() .flatMap(AiServiceMethodCreateInfo.TemplateInfo::text); - return userMessageTemplateOpt.orElse(null); + return userMessageTemplateOpt.orElse(EMPTY); } public record UserMessageInfo(Optional template,