Skip to main content

Overview

Evaluators are functions that assess agent performance on specific criteria. This reference documents the evaluator patterns and implementations used in the Building Reliable Agents course for testing schema checking, conciseness, and other behavioral aspects.

Schema Checking Evaluators

schema_before_query()

Verifies that agents check database schema before executing data queries.
Run
required
LangSmith Run object containing the agent execution trace with outputs and messages
Example
required
LangSmith Example object containing the test case data (not used in this evaluator)
int
  • 1: Agent checked schema before querying data (or made no database calls)
  • 0: Agent queried data without checking schema first
str
Explanation of the score with details about what was found
Example:
Key Concepts:
  • Schema Patterns: Regex patterns that identify schema inspection queries
  • Tool Call Extraction: Parse agent output to find all database tool calls
  • Sequential Checking: Verify schema check happens before first data query
  • Not Applicable Cases: Return score of 1 when no database queries are made

Pairwise Comparison Evaluators

conciseness_evaluator()

Compares two agent responses for conciseness while preserving crucial information.
dict
required
Dictionary containing:
  • question: The user’s question both agents answered
list[dict]
required
List of two output dictionaries, each containing:
  • answer: The agent’s response text
list[int]
List of two scores:
  • [1, 0]: First response is more concise
  • [0, 1]: Second response is more concise
  • [0, 0]: Both are roughly equal in conciseness
Example:
Pairwise Evaluation:

Simple Code-Based Evaluators

String Matching Evaluator

Check if response contains specific text.

Custom Scoring Evaluator

Return a numeric score with explanation.

LLM-as-Judge Evaluators

Use an LLM to evaluate agent outputs.

Binary Classification

Multi-Criteria Evaluation

Running Evaluations

Single Agent Evaluation

Pairwise Comparison

Multiple Evaluators

Evaluator Return Formats

Boolean Return

Simplest form - returns pass/fail.

Dictionary Return

Provides score and explanation.

Pairwise Return

Returns list of scores for comparison.

Best Practices

Clear Criteria

Define evaluation criteria explicitly:

Helpful Comments

Provide actionable feedback:

Metadata

Include diagnostic information:

Robust Parsing

Handle missing or malformed data: