Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Arize ai Phoenix ExactMatch

From Leeroopedia

Overview

exact_match is a code-based evaluator function in the arize-phoenix-evals package that performs strict string equality comparison between an output and an expected value. It is decorated with @create_evaluator to conform to the standard Evaluator interface, returning a Score of 1.0 for an exact match and 0.0 otherwise.

Description

The exact_match evaluator is the simplest metric in the phoenix-evals metrics module. It performs a direct equality check (output == expected) with no text normalization applied -- no case folding, whitespace trimming, or Unicode normalization. The comparison is case-sensitive and whitespace-sensitive.

The function is wrapped with the @create_evaluator decorator, which:

  • Registers it as an evaluator with the name "exact_match" and kind "code".
  • Enables it to accept a dictionary eval_input and optional field_mapping parameter.
  • Makes it compatible with the standard evaluator interface used by evaluate_dataframe and other evaluation utilities.

Usage

from phoenix.evals.metrics import exact_match

Code Reference

Property Value
Source File packages/phoenix-evals/src/phoenix/evals/metrics/exact_match.py
Module phoenix.evals.metrics.exact_match
Function exact_match(output: str, expected: str) -> Score
Decorator @create_evaluator(name="exact_match", kind="code")
Lines ~37
Kind "code"
Direction "maximize"
Domain LLM Evaluation, Metrics

Implementation

The core logic is minimal:

@create_evaluator(name="exact_match", kind="code")
def exact_match(output: str, expected: str) -> Score:
    correct = output == expected
    return Score(score=float(correct))

I/O Contract

Input

Field Type Required Description
output str Yes The output text to evaluate.
expected str Yes The expected (ground-truth) text.

Note: Input field names can be remapped using the field_mapping parameter if the eval input dictionary uses different key names.

Output

Returns a list containing one Score object:

Field Description
name "exact_match"
score 1.0 if output == expected, 0.0 otherwise.
label True or False.
explanation None
kind "code"
direction "maximize"

Usage Examples

Direct Usage (No Field Mapping)

from phoenix.evals.metrics import exact_match

eval_input = {"output": "no", "expected": "yes"}
scores = exact_match(eval_input)
print(scores)
# [Score(score=0.0, name='exact_match', label=False, explanation=None,
#  direction='maximize', kind='code', metadata={})]

Usage with Field Mapping

from phoenix.evals.metrics import exact_match

eval_input = {"prediction": "yes", "gold": "yes"}
field_mapping = {"output": "prediction", "expected": "gold"}
scores = exact_match(eval_input, field_mapping=field_mapping)
print(scores)
# [Score(score=1.0, name='exact_match', label=True, explanation=None,
#  direction='maximize', kind='code', metadata={})]

Case Sensitivity

from phoenix.evals.metrics import exact_match

# Case-sensitive: "Paris" != "paris"
eval_input = {"output": "paris", "expected": "Paris"}
scores = exact_match(eval_input)
# score=0.0 -- no normalization is performed

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment