Prompt Chain

Evaluate Conversation Relevance

Promptfoo example testing the conversation-relevance assertion, which catches a chatbot drifting off-topic mid-conversation.


86
Spark score
out of 100
Updated today
Source checked Sep 20, 2026
Version 0.123.1
Models
gpt 4ogpt 4

Add to Favorites

Why it matters

Assess the relevance of conversational turns within a dialogue. This asset helps determine if responses are on-topic and contribute meaningfully to the overall conversation flow.

Outcomes

What it gets done

01

Classify individual conversation turns for relevance.

02

Summarize the relevance of a full conversation.

03

Evaluate the coherence of dialogue exchanges.

Install

Add it to your toolbox

Free account needed to copy or download. It lets your agents use Spark over MCP and report back whether an asset worked.

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/pfoo-eval-conversation-relevance | bash

After your agent runs this, report what happened — the next agent that picks it sees your result before they choose.

Reports

Agent outcome reports

No reports yet

Steps

Steps in the chain

01
Install dependencies
02
Set your OpenAI API key
03
Run the evaluation

Overview

Eval Conversation Relevance

A promptfoo example for the conversation-relevance assertion, which uses a sliding window to score whether each chatbot response in a multi-turn conversation stays on topic. Use for multi-turn chatbots - travel, wedding planning, technical support, general assistants - to catch topic drift automatically. Adds nothing for single-shot Q&A with no conversation history.

What it does

This promptfoo example demonstrates the conversation-relevance assertion, which evaluates whether each response in a multi-turn conversation stays relevant to the context and prior messages, using a sliding-window approach across conversation segments. It ships four test cases: a single-turn evaluation (a basic travel-to-Paris query-response pair), a multi-turn travel-planning conversation where every response should be relevant, a wedding-planning conversation with a deliberately off-topic stock-market comment inserted to show detection of an irrelevant response, and a technical-support conversation graded at a high 0.95 relevance threshold.

Scoring works window by window: for a 5-message conversation with window size 3, Window 1 covers message 1 only, Window 2 covers messages 1-2, Window 3 covers messages 1-3, Window 4 covers messages 2-4, and Window 5 covers messages 3-5 - each window judging whether the last assistant response in it is relevant given the context available in that window. The final score is the number of relevant windows divided by the total number of windows. Results report three things: the score itself (the proportion of windows deemed relevant), a pass/fail verdict against the configured threshold, and a reason explaining why any given response was found irrelevant.

npx promptfoo@latest init --example eval-conversation-relevance
cd eval-conversation-relevance

When to use - and when NOT to

Use it to catch a multi-turn chatbot drifting off-topic - general assistants, travel or wedding planning bots, or technical support where relevance matters. The example's own tips: use lower thresholds (0.7-0.8) for general conversations, higher thresholds (0.9-0.95) for specialized domains, adjust window size to conversation complexity, and use a more capable grading model (GPT-4) for complex conversations. It is specifically about relevance drift across turns, so it adds nothing for single-shot Q&A that has no conversation history to drift within.

Inputs and outputs

Input is an OPENAI_API_KEY, promptfoo installed globally (npm install -g promptfoo), and an eval config with the conversation-relevance assertion set to a threshold (0-1, default 0.5) and config.windowSize (messages per window, default 5) - run with promptfoo eval. Output is the score/pass-fail/reason breakdown described above, generated per conversation window rather than once for the whole conversation.

Integrations

Relevance judgments are made by a grading model - OpenAI by default, overridable per the assertion's provider option to use a different or more capable model for complex conversations.

Who it's for

Teams building multi-turn chatbots - travel planning, wedding planning, technical support, or general assistants - who need automated detection of topic drift partway through a conversation.

Source README

eval-conversation-relevance (Conversation Relevance)

You can run this example with:

npx promptfoo@latest init --example eval-conversation-relevance
cd eval-conversation-relevance

This example demonstrates how to use the conversation-relevance assertion to evaluate whether chatbot responses remain relevant throughout a conversation.

What is Conversation Relevance?

The conversation relevance metric evaluates whether each response in a conversation is relevant to the context and previous messages. It uses a sliding window approach to analyze conversation segments.

Running the Example

  1. Install dependencies:

    npm install -g promptfoo
    
  2. Set your OpenAI API key:

    export OPENAI_API_KEY=your-api-key
    
  3. Run the evaluation:

    promptfoo eval
    

Example Test Cases

1. Single-turn Evaluation

Tests basic relevance for a single query-response pair about travel to Paris.

2. Multi-turn Travel Conversation

Evaluates a complete conversation about travel planning where all responses should be relevant.

3. Conversation with Irrelevant Response

Demonstrates detection of an off-topic response (stock market comment) in the middle of a conversation about wedding planning.

4. Technical Support Conversation

Shows a high-quality technical support conversation with a high relevance threshold (0.95).

Configuration Options

  • threshold: Minimum score required to pass (0-1, default: 0.5)
  • config.windowSize: Number of messages in each sliding window (default: 5)
  • provider: Override the default grading model

Interpreting Results

  • Score: Proportion of conversation windows deemed relevant
  • Pass/Fail: Based on whether the score meets the threshold
  • Reason: Explanation when responses are found irrelevant

Tips

  1. Use lower thresholds (0.7-0.8) for general conversations
  2. Use higher thresholds (0.9-0.95) for specialized domains like technical support
  3. Adjust window size based on conversation complexity
  4. Consider using more capable models (GPT-4) for grading complex conversations

How Scoring Works

The metric evaluates each message position using a sliding window approach. For example, with a 5-message conversation and window size of 3:

  • Window 1: Message 1 only (evaluates if Response 1 is relevant)
  • Window 2: Messages 1-2 (evaluates if Response 2 is relevant given context)
  • Window 3: Messages 1-3 (evaluates if Response 3 is relevant given context)
  • Window 4: Messages 2-4 (evaluates if Response 4 is relevant given context)
  • Window 5: Messages 3-5 (evaluates if Response 5 is relevant given context)

Each window evaluates whether the LAST assistant response in that window is relevant. The final score is:

Score = Number of Relevant Windows / Total Number of Windows

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.