When to Use Pairwise Evaluation
Use pairwise comparison when:- Comparing agent versions - Which agent is more concise, helpful, or accurate?
- Relative quality matters - It’s easier to say “A is better than B” than “A scores 0.73”
- Subjective criteria - Conciseness, tone, style
- A/B testing decisions - Which version should go to production?
Pairwise evaluation works best for comparing two versions on the same dataset. For evaluating a single agent, use standard evaluators instead.
Basic Pairwise Evaluation
Run experiments on both agents, then compare:Real-World Example: Conciseness Comparison
This example from the OfficeFlow course compares two agent versions on conciseness:eval_conciseness_pairwise.py
randomize_order=True is critical - it prevents position bias where the LLM might favor the first or second response systematically.Complete Workflow
Here’s how to run both agents and compare them in one script:run_pairwise_experiment.py
Pairwise Evaluator Patterns
Simple Preference
The evaluator returns[1, 0], [0, 1], or [0, 0]:
preference_scores.py
Strength of Preference
Return scores showing how much better one is:preference_strength.py
Multiple Criteria
Compare on several dimensions:multi_criteria_pairwise.py
Best Practices
Always Randomize Order
Prevent position bias:always_randomize.py
Provide Clear Criteria
Define what “better” means:clear_criteria.py
Use Descriptive Evaluation Names
descriptive_names.py
Consider Multiple Judges
Use multiple models or run multiple times for confidence:multiple_judges.py
Interpreting Results
Pairwise results show:- Win rate: How often each agent won
- Tie rate: How often outputs were equivalent
- Per-example comparison: Which specific inputs show differences
Statistical Significance
For small datasets, a few wins might not be meaningful:significance.py
Common Use Cases
Prompt Engineering
Compare prompt variations:prompt_comparison.py
Model Selection
Compare different models:model_comparison.py
Configuration Tuning
Compare temperature, max_tokens, etc.:config_comparison.py
Limitations
Only Compares Two at a Time
For more than two versions, run multiple pairwise comparisons:multi_version.py
Subject to LLM Biases
Mitigate by:- Always randomizing order
- Using clear rubrics
- Running multiple evaluations
- Using multiple judge models
Next Steps
Create Datasets
Build test datasets for evaluation
LLM-as-Judge
Deep dive into LLM evaluation