Skip to main content

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:
Characteristics:
  • 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:
Characteristics:
  • 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:
Characteristics:
  • Better for A/B testing agent versions
  • More reliable than absolute scoring
  • Requires running experiments on both variants
  • Use randomizeOrder: true to 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

  1. Be specific in comments - Help developers understand failures
  2. Handle edge cases - Return appropriate scores for N/A cases
  3. Keep them fast - They run on every test case

LLM-as-Judge Evaluators

  1. Use clear rubrics - Define exactly what you’re measuring
  2. Request structured output - Numbers or specific formats
  3. Test your prompts - Run on sample data first
  4. Consider cost - LLM calls add up on large datasets

Pairwise Evaluators

  1. Randomize order - Prevent position bias
  2. Handle ties - Score both as 0 for equal performance
  3. Provide context - Include the original question in prompts
  4. Be consistent - Use same criteria across all comparisons