quarkiverse / quarkus-langchain4j

Quarkus Langchain4j extension
https://docs.quarkiverse.io/quarkus-langchain4j/dev/index.html
Apache License 2.0
148 stars 89 forks source link

Provide original input text to outputguard #1064

Closed lordofthejars closed 2 weeks ago

lordofthejars commented 2 weeks ago

In some output guards, we would need the original input text to validate the output. For example, I want to validate that the output of the LLM is in the same language as the input text, and if not reprompt.

Another use case could be to ask to the model if the response is accurate to the question given initially

I think now this is not possible now in the output guardrails, but I might be wrong.

dennysfredericci commented 2 weeks ago

This already exists.

public class OutputGuardRailExample implements OutputGuardrail {

    @Override
    public OutputGuardrailResult validate(OutputGuardrailParams params) {
        params.userMessageTemplate(); // The input text should be here.
        params.variables(); // If there are variables in the user message, they should be here.

        // ...

        return this.success();
    }
}
lordofthejars commented 2 weeks ago

Thanks