Skip to content

Conversation

@JoonasVali
Copy link

@JoonasVali JoonasVali commented Dec 25, 2025

Problem:

The RelevancyEvaluator is a black box at the moment, which evaluates the content without providing any explanation about why it came to such conclusion. Furthermore the code relies on dated method of forcing the LLM to respond in a structured manner without using the spring-ai's structured output option.

Solution:

Modify the RelevancyEvaluator in a backwards compatible way to offer a new feedbackEnabled(boolean feedbackEnabled) method in the Builder, which would enable the evaluator to use structured output with a response type that offer both the answer, and the accompanying reasoning behind it.

record Response(
			@JsonPropertyDescription("Provides a short explanation how the query is or is not in line with the context information provided")
			String reasoning,
			@JsonPropertyDescription("Indicates whether the response for the query is in line with the context information provided")
			boolean isInLine) {
	}

The reasoning is then mapped to EvaluationResponse's existing feedback field, which was currently unused and always left as an empty String.

The existing solution is kept working by default so that the change would not break existing flows or change the nature of the LLM calls, potentially disrupting token usage and bias in the prompt.

Additional notes

FactCheckingEvaluator faces a similar problem, but I didn't want to change it unless the method is validated by the maintainers as useful and worth doing.

Example request body, when feedbackEnabled is set true.

	Your task is to evaluate if the response for the query
	is in line with the context information provided.

	Query:
	${query here}

	Response:
	${response here}

	Context:
	${context here}



Your response should be in JSON format.
Do not include any explanations, only provide a RFC8259 compliant JSON response following this format without deviation.
Do not include markdown code blocks in your response.
Remove the ```json markdown from the output.
Here is the JSON Schema instance your output must adhere to:
```{
  "$schema" : "https://json-schema.org/draft/2020-12/schema",
  "type" : "object",
  "properties" : {
    "isInLine" : {
      "type" : "boolean",
      "description" : "Indicates whether the response for the query is in line with the context information provided"
    },
    "reasoning" : {
      "type" : "string",
      "description" : "Provides a short explanation of how the response for the query is or is not in line with the context information provided"
    }
  },
  "additionalProperties" : false
}```

Signed-off-by: Joonas Vali <joonas.wali@gmail.com>
Signed-off-by: Joonas Vali <joonas.wali@gmail.com>
@JoonasVali JoonasVali marked this pull request as ready for review December 25, 2025 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant