liveBook · Manning

Chapter 2: Evaluating generated responses

What you will learn in chapter 2 of Spring AI in Action

This introduction explains why ordinary assertions and mocked responses cannot fully test generative AI behavior, then introduces Spring AI evaluators as a way to judge generated answers.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction explains why ordinary assertions and mocked responses cannot fully test generative AI behavior, then introduces Spring AI evaluators as a way to judge generated answers.

Key terms: nondeterministic, assert equals, WireMock, evaluator, user text, response content, ChatClient

2.1 Ensuring relevant answers

This section defines answer relevance and shows how to test it with Spring AI’s RelevancyEvaluator.

Key terms: relevant, factual accuracy, BoardGameService, EvaluationRequest, RelevancyEvaluator, EvaluationResponse, isPass()

2.2 Testing for factual accuracy

This section explains why relevant answers still need fact-checking and how a Spring AI test can flag generated answers judged incorrect.

Key terms: RelevancyEvaluator, FactCheckingEvaluator, factual accuracy, EvaluationResponse, isPass(), evaluateFactualAccuracy(), evaluateRelevancy(), prompt

2.3 Applying self-evaluation at runtime

This section shows how to check answer relevance at runtime, retry failed answers, and recover when retries are exhausted.

Key terms: evaluators, runtime, nondeterministic, RelevancyEvaluator, isPass(), AnswerNotRelevantException, @Retryable, @Recover, maxAttempts, tokens

2.4 Summary

Concepts explained in this chapter

← Chapter 1: Getting started with Spring AI Chapter 3: Submitting prompts for generation →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.