# 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

| Parameter    | Type          | Required | Default | Description                                                                  |
| ------------ | ------------- | -------- | ------- | ---------------------------------------------------------------------------- |
| `fn`         | `Callable`    | ✓        | `-`     | The callable function to wrap as an evaluator.                               |
| `score_name` | `str \| None` | ✗        | `None`  | Optional custom name for the score. If not provided, uses the function name. |

## Example

```python
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)

        # Invalid arguments raise TypeError
        try:
                evaluator.score(wrong_param="value")
            except TypeError as e:
                    print(f"Error: {e}")
```

## *property* name *: 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

| Parameter  | Type  | Required | Default | Description                                                                                                   |
| ---------- | ----- | -------- | ------- | ------------------------------------------------------------------------------------------------------------- |
| `*args`    | `Any` | ✗        | `-`     | Positional arguments to pass to the wrapped function.                                                         |
| `**kwargs` | `Any` | ✗        | `-`     | Keyword arguments to pass to the wrapped function. Only kwargs that match the function's parameters are used. |

### Returns

A Score object representing the function's evaluation result.

**Return type:** Score

### Raises

**TypeError** – If the provided arguments don't match the function signature.

{% hint style="info" %}
The function result is converted to a Score as follows:

* bool: 1.0 for True, 0.0 for False
* int/float: Direct value conversion
* Score: Returns as-is
  {% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fiddler.ai/api/fiddler-evals-sdk/evaluators/eval-fn.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
