Overview
Evaluators are functions that assess agent runs based on specific criteria. They integrate with LangSmith’s evaluation framework to provide automated quality checks and comparative analysis.Schema Validation
schemaBeforeQuery()
Verifies that the agent checks database schema before executing data queries.Run
required
LangSmith run object containing execution trace
string
Evaluator identifier:
"schema_before_query"number
Binary score: 1 if agent checked schema first, 0 otherwise
string
Explanation of the evaluation result
Schema Query Detection
The evaluator identifies schema queries using regex patterns:Tool Call Extraction
Helper function to extract tool calls from run outputs:Usage Example
Pairwise Comparison
concisenessEvaluator()
Compares two agent responses for conciseness using LLM-as-a-judge.Record<string, any>
required
Test case inputs containing the question
Run[]
required
Array of exactly two runs to compare
string
Evaluator identifier:
"conciseness"Record<string, number>
Map of run IDs to scores (winner gets 1, loser gets 0)
Running Pairwise Evaluation
Simple Evaluators
mentionsOfficeflow()
Example code-based evaluator that checks if response mentions the company name.Record<string, any>
required
Run outputs containing the response
string
Evaluator identifier:
"mentions_officeflow"boolean
True if response mentions “officeflow” (case-insensitive)
Usage Example
Evaluation Types
Code-Based Evaluators
Deterministic functions that check specific conditions:- Fast and cheap to run
- Deterministic results
- Good for structural checks (schema validation, format checking)
- Limited to rule-based logic
LLM-as-Judge Evaluators
Use language models to assess quality:- Can assess subjective qualities (tone, helpfulness, conciseness)
- More expensive and slower
- Non-deterministic (may vary between runs)
- Requires careful prompt engineering
Pairwise Evaluators
Compare two runs directly:- Better for A/B testing agent versions
- More reliable than absolute scoring
- Requires running experiments on both variants
- Use
randomizeOrder: trueto avoid position bias
Integration with LangSmith
Running Evaluations
Evaluation Results
Results are logged to LangSmith and include:- Individual test case scores
- Aggregate statistics
- Comparison charts (for pairwise)
- Trace links for debugging failures
Best Practices
Code-Based Evaluators
- Be specific in comments - Help developers understand failures
- Handle edge cases - Return appropriate scores for N/A cases
- Keep them fast - They run on every test case
LLM-as-Judge Evaluators
- Use clear rubrics - Define exactly what you’re measuring
- Request structured output - Numbers or specific formats
- Test your prompts - Run on sample data first
- Consider cost - LLM calls add up on large datasets
Pairwise Evaluators
- Randomize order - Prevent position bias
- Handle ties - Score both as 0 for equal performance
- Provide context - Include the original question in prompts
- Be consistent - Use same criteria across all comparisons