LLM applications can be challenging to evaluate since they often generate conversational text with no single correct answer. This guide shows you how to define an LLM-as-a-judge evaluator for offline evaluation using the LangSmith SDK.
For a quick start, use openevals, which provides ready-to-use LLM-as-a-judge evaluators.

Create your own LLM-as-a-judge evaluator

For complete control of evaluator logic, create your own LLM-as-a-judge evaluator and run it using the LangSmith SDK (Python / TypeScript). Requires langsmith>=0.2.0 An LLM-as-a-judge evaluator consists of three key components:
  1. Evaluator function: A function that receives the example inputs and application outputs, then uses an LLM to score the quality. The function should return a boolean, number, string, or dictionary with score information.
  2. Target function: Your application logic being evaluated (wrapped with @traceable for observability).
  3. Dataset and evaluation: A dataset of test examples and the evaluate() function that runs your target function on each example and applies your evaluators.

Example

For more information on how to write a custom evaluator, refer to How to define a code evaluator (SDK).