> ## 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.

# EvalFn

> Evaluator that wraps a user-provided function for dynamic evaluation.

This class allows users to create evaluators from any callable function,
automatically handling parameter passing, validation, and result conversion to Score objects.

Key Features:

* **Dynamic Function Wrapping**: Converts any callable into an evaluator
* **Argument Validation**: Validates that provided arguments match function signature
* **Smart Result Conversion**: Automatically converts various return types to Score
* **Error Handling**: Gracefully handles function execution and argument errors
* **Parameter Flexibility**: Supports functions with any parameter signature

## Parameters

**fn** `Callable` *required*

The callable function to wrap as an evaluator.

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

Optional custom name for the score. If not provided,
uses the function name.

## Example

```python theme={null}
from fiddler_evals import EvalFn
from fiddler_evals.exceptions import ScoreFunctionInvalidArgs

def equals(a, b):
    return a == b

evaluator = EvalFn(equals, score_name="exact_match")
score = evaluator.score(a="hello", b="hello")
print(score.value)  # 1.0

def length_check(text, min_length=5):
    return len(text) >= min_length

evaluator = EvalFn(length_check)

# Arguments that don't fit the wrapped function's signature raise
# ScoreFunctionInvalidArgs
try:
    evaluator.score(wrong_param="value")
except ScoreFunctionInvalidArgs as e:
    print(f"Error: {e}")
```

## *property* name

**Type:** `str`

## score()

Execute the wrapped function and convert result to Score.

Calls the wrapped function with the provided arguments and converts
the result to a Score object. Validates that the provided arguments
match the function's signature.

### Parameters

\***args** `Any`

Positional arguments to pass to the wrapped function.

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

Keyword arguments to pass to the wrapped function. They
must match its parameters: an unknown keyword raises
`ScoreFunctionInvalidArgs` unless the function accepts
`**kwargs`.

### Returns

A [`Score`](https://docs.fiddler.ai/sdk-api/evals/score) object representing the function's evaluation result, or the list of Score objects the wrapped function returned.

### Raises

**ScoreFunctionInvalidArgs** – If the provided arguments don't match the
wrapped function's signature.

> [!NOTE]
>
> The wrapped function's return value is converted to a Score as follows:
>
> * `bool`: value 1.0 for True, 0.0 for False, with `label` set to
>   the string form ("True" / "False")
> * `int` / `float`: value set to the number
> * [`Score`](https://docs.fiddler.ai/sdk-api/evals/score): returned as-is
> * `list[Score]`: returned as-is
> * `None`: a SKIPPED score
> * anything else: `label` set to the string form of the value

Exceptions raised inside the wrapped function do not stop the run.
Raising [`SkipEval`](https://docs.fiddler.ai/sdk-api/evals/skip-eval) produces a SKIPPED score, and any other exception
produces a FAILED score carrying the error reason and message.
