Skip to main content

Overview#

The exact_match evaluator is a simple code-based evaluator that checks if the output exactly equals the expected value. It performs a strict string comparison with no normalization.

Note

This evaluator is only available as a built-in for Python. For TypeScript, see the usage example below showing how to create an equivalent evaluator using createEvaluator.

When to Use#

Use the exact_match evaluator when you need to:

  • Validate exact outputs - Check that responses match expected values character-for-character
  • Evaluate classification tasks - Verify categorical outputs match expected labels
  • Test deterministic outputs - Validate outputs that should be identical every time
  • Quick sanity checks - Fast evaluation without LLM costs
Info

This is a code-based evaluator that performs direct string comparison. For semantic similarity or fuzzy matching, consider using an LLM-based evaluator instead.

Supported Levels#

LevelSupportedNotes
SpanYesEvaluate any span output against expected values.

Input Requirements#

The exact_match evaluator requires two inputs:

FieldTypeDescription
outputstringThe actual output to evaluate
expectedstringThe expected value to match against

Important Notes#

  • No normalization: The comparison is case-sensitive and whitespace-sensitive
  • String comparison: Both inputs are compared as strings
  • No partial matching: The entire string must match exactly

Output Interpretation#

The evaluator returns a Score object with the following properties:

PropertyValueDescription
labelTrue or FalseWhether the strings match
score1.0 or 0.0Numeric score (1.0 = match, 0.0 = no match)
kind"code"Indicates this is a code-based evaluator
direction"maximize"Higher scores are better

Usage Examples#

Implementing Case-Insensitive Matching#

If you need case-insensitive matching, normalize your inputs first:

Or create a custom evaluator with normalization:

Using with Phoenix#

Evaluating Traces#

Run evaluations on traces collected in Phoenix and log results as annotations:

Running Experiments#

Use the exact_match evaluator in Phoenix experiments:

API Reference#