> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fiddler.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Evaluator

> Abstract base class for creating custom evaluators in Fiddler Evals.

The Evaluator class provides a flexible framework for creating builtin and custom evaluators
that can assess LLM outputs against various criteria. Each evaluator is
responsible for a single, specific evaluation task (e.g., hallucination detection,
answer relevance, exact match, etc.).

Parameter Mapping:
Evaluators can define their own parameter mappings using score\_fn\_kwargs\_mapping
in the constructor. These mappings specify how data from the evaluation context
(inputs, outputs, expected\_outputs) should be passed to the evaluator's score method.

Mapping Priority (highest to lowest):

1. Evaluator-level score\_fn\_kwargs\_mapping (set in constructor)
2. Evaluation-level kwargs\_mapping (passed to evaluate function)
3. Default parameter resolution

This allows evaluators to define sensible defaults while still permitting
customization at the evaluation level.

Creating Custom Evaluators:
To create a custom evaluator, inherit from this class and implement the score method
with parameters specific to your evaluation needs:

Example - Custom evaluator with parameter mapping:
class ExactMatchEvaluator(Evaluator):

> def **init**(self, output\_key: str = "answer", score\_name\_prefix: str = None):
> : super().**init**(
> : score\_name\_prefix=score\_name\_prefix,
> score\_fn\_kwargs\_mapping=\{"output": output\_key}
>
> )

> def score(self, output: str, expected\_output: str) -> Score:
> : is\_match = output.strip().lower() == expected\_output.strip().lower()
> return Score(
>
> > name=f"\{self.score\_name\_prefix}exact\_match",
> > evaluator\_name=self.name,
> > value=1.0 if is\_match else 0.0,
> > reasoning=f"Match: \{is\_match}"
>
> )

## Parameters

**score\_name\_prefix** `str | None` (default: None)

Optional prefix to prepend to score names. Useful for
distinguishing scores when using multiple instances of the same evaluator
on different fields or with different configurations.

**score\_fn\_kwargs\_mapping** `ScoreFnKwargsMappingType | None` (default: None)

Optional mapping for parameter transformation.
Maps parameter names to either string keys or transformation functions.
This mapping takes precedence over evaluation-level mappings when running
the evaluate method.

> [!NOTE]
>
> The score method signature is intentionally flexible using \*args and \*\*kwargs
> to allow each evaluator to define its own parameter requirements. This design
> enables maximum flexibility while maintaining a consistent interface across
> all evaluators in the framework.

Initialize the evaluator with parameter mapping configuration.

## Parameters

**score\_name\_prefix** `str | None` (default: None)

Optional prefix to prepend to score names. Useful for
distinguishing scores when using multiple instances of the same evaluator
on different fields or with different configurations.

**score\_fn\_kwargs\_mapping** `Dict[str, str | Callable[[Dict[str, Any]], Any]] | None` (default: None)

Optional mapping for parameter transformation.
Maps parameter names to either string keys or transformation functions.
This mapping takes precedence over evaluation-level mappings when running
the evaluate method.

## Example

```python theme={null}
# Simple string mapping
evaluator = MyEvaluator(score_fn_kwargs_mapping={"output": "answer"})

# Complex transformation function
evaluator = MyEvaluator(score_fn_kwargs_mapping={
    "question": lambda x: x["inputs"]["question"],
    "response": "answer"
})

# Using score name prefix for multiple instances
evaluator1 = RegexSearch(r"\d+", score_name_prefix="question")
evaluator2 = RegexSearch(r"\d+", score_name_prefix="answer")
# Results in scores named "question_has_number" and "answer_has_number"
```

## Raises

**ScoreFunctionInvalidArgs** – If the mapping contains invalid parameter names
that don't match the evaluator's score method signature.

## *property* name

**Type:** `str`

## *abstractmethod* score()

Evaluate inputs and return a score or list of scores.

This method must be implemented by all concrete evaluator classes.
Each evaluator can define its own parameter signature based on what
it needs for evaluation.

Common parameter patterns:

* Output-only: score(self, output: str) -> Score
* Input-Output: score(self, input: str, output: str) -> Score
* Comparison: score(self, output: str, expected\_output: str) -> Score
* All parameters: score(self, input: str, output: str, context: list\[str]) -> Score

The runner resolves each parameter by name. Alongside the task's outputs,
which are spread into the namespace by key, four parameters are always
available – declare only the ones you need:

* `inputs` (`dict`) – the dataset item's inputs, passed as a single
  dict rather than spread.
* `outputs` (`dict`) – everything the task returned.
* `expected_outputs` (`dict | None`) – the item's expected outputs.
* `session` (`Session | None`) – the OpenTelemetry spans captured
  while the task ran. Declaring it opts the evaluator in to scoring the
  execution itself (tool call order, retry counts, token usage, latency)
  rather than only the final output string. Trace capture is best-effort,
  so default it to `None` and handle that case.

All four are bound after the task outputs are spread, so a task output of
the same name cannot shadow them.

### Parameters

\***args** `Any`

Positional arguments specific to the evaluator's needs.

\*\***kwargs** `Any`

Keyword arguments specific to the evaluator's needs.

### Returns

A single [`Score`](https://docs.fiddler.ai/sdk-api/evals/score) object or list of Score objects
representing the evaluation results. Each Score should include:

* name: The score name (e.g., "has\_zipcode")
* evaluator\_name: The evaluator name (e.g., "RegexMatch")
* value: The score value (typically 0.0 to 1.0)
* status: SUCCESS, FAILED, or SKIPPED
* reasoning: Optional explanation of the score
* error: Optional error information if evaluation failed

### Raises

* **ValueError** – If required parameters are missing or invalid.
* **TypeError** – If parameters have incorrect types.
* **Exception** – Any other evaluation-specific errors.
