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

# Custom Evaluators

> Build a workflow that evaluates the output of workflows and snippets by your own rules

In an [evaluation](https://enterprise-docs.dify.ai/en/3.14.x/use/evaluate/run-evaluations.md), [built-in metrics](https://enterprise-docs.dify.ai/en/3.14.x/use/evaluate/metrics.md) answer general questions, for example whether an answer is grounded in its sources or matches a reference. For a rule of your own, such as a required format, a length limit, or a rubric in your own words, build a *custom evaluator*.

A custom evaluator works only in evaluations of Workflow apps and [snippets](https://enterprise-docs.dify.ai/en/3.14.x/use/build/snippet.md). It can grade against your rubric with an LLM node, run an exact check in a Code node, or do both. Its outputs then work like built-in metrics, and judgment conditions can pass or fail rows on them.

## How a Custom Evaluator Works

A custom evaluator is a Workflow app that you publish as an *evaluation workflow*. The evaluation runs it once for each row of the test set.

The evaluator's User Input node receives values you choose from that row's run of the evaluated workflow: an input variable, such as the question, or a node's output, such as the answer. The evaluator can't read your test set's reference answers, so leave comparisons with them to the built-in metrics.

Each variable of the evaluator's Output node comes back as one of the row's *custom metrics*.

An evaluation takes one custom evaluator. To check several rules, put them all in one evaluator, with a separate output for each rule you want to judge on its own.

The evaluator's runs are ordinary runs of its app. They appear in its **Logs**, one for each row it runs on.

## Build the Evaluator

Say your support workflow takes a `question`, retrieves passages from a knowledge base, and has an LLM node answer from them. Your team wants every answer to follow its style: answer the question that was asked, stay under about 120 words, and end with a next step the user can take.

To check these rules, create a Workflow app and name it `Support Style Check`. An evaluation workflow can't contain Trigger nodes or Human Input nodes, so leave those out.

> [!TIP]
>
> To try this evaluator in your workspace, get [its template](https://marketplace.dify.ai/template/riskey/59ad14f7-1ddc-4692-ba02-a676b77c72bc) from Dify Marketplace.

### Take In the Values to Check

In the User Input node, add an input variable for each value the evaluator will receive. To tell whether an answer addresses its question, the evaluator needs both, so add two Paragraph variables: `question` and `answer`.

### Score the Answer Against Your Rules

Choose the scoring node by the rule:

* A rule that takes judgment, such as whether an answer addresses its question, needs an LLM node with your rubric.
* A rule a script can check exactly, such as a word count or a required value, fits a Code node.

Here, the length limit is only approximate, so one LLM node can judge all three rules.

Add an LLM node named `Style Check` and set its temperature to 0, since a scorer should give the same answer the same score every time. Write the rules into its system instruction, along with the score each outcome earns:

```text wrap theme={null}
You review a support answer against three style rules:
1. It answers the question that was asked.
2. It is under about 120 words.
3. It ends with a next step the user can take.

Give a score between 0 and 1: 1 if all three rules are met, 0.67 if two are met, 0.33 if one is met, 0 if none.
Give a one-line reason that names any rule the answer breaks.
```

Naming the score for each outcome means two answers that break the same rule get the same score. The one-line reason then shows you, in the results, which rule an answer broke.

In the user message, insert the two input variables:

```text theme={null}
Question: {{question}}
Answer: {{answer}}
```

### Return Scores Your Conditions Can Test

Each output becomes a metric, and its type decides how a judgment condition can test it:

* **Number** (integer or decimal), such as a `score`: compared with a threshold, such as ≥ 0.8
* **Boolean**, such as a `passed` flag: checked as true or false
* **String**, such as a `reason`, and any other type: compared as text, for example with contains

A score you'll set a threshold on has to be a number. Go back to `Style Check`, turn on [structured output](https://enterprise-docs.dify.ai/en/3.14.x/use/nodes/llm.md#structured-outputs), and add two required fields:

| Field | Type | Description |
| :- | :- | :- |
| `score` | number | Score between 0 and 1 |
| `reason` | string | One-line reason |

Then add both fields to the [Output](https://enterprise-docs.dify.ai/en/3.14.x/use/nodes/output.md) node:

* `score`, from `Style Check`'s `structured_output.score`
* `reason`, from `Style Check`'s `structured_output.reason`

## Publish It as an Evaluation Workflow

> [!NOTE]
>
> Publishing or switching an evaluation workflow requires the **Publish and manage app versions** permission.

Run the evaluator once in the editor with a sample question and answer. If the `score` and `reason` it returns look right, open the **Publish** menu and click **Publish as Evaluation Workflow**.

To turn a workflow that's already published into an evaluator, choose **Switch to Evaluation Workflow** instead. It converts the version that's currently published, so publish any draft changes first.

An evaluation workflow can be turned back into a standard one, but evaluations that use it can't run until it's an evaluation workflow again.

## Add It to an Evaluation

Open the support workflow's **Evaluation** page, click **Add Metric** > **Custom metrics**, and select `Support Style Check`. If an evaluator a teammate built isn't listed, ask for [access](https://enterprise-docs.dify.ai/en/3.14.x/use/workspace/roles-and-permissions#control-who-can-access-a-resource) to its app and the **Test and use app** permission on it.

Under **Variable Mapping**, choose what each of the evaluator's input variables receives from the support workflow's published version:

* `question`, from the User Input node's `question`
* `answer`, from the LLM node's `text`, the answer itself

If the evaluated workflow branches, map from nodes that run on every path. When the answer comes from a different node on each branch, join them with a [Variable Aggregator](https://enterprise-docs.dify.ai/en/3.14.x/use/nodes/variable-aggregator.md) node and map from it.

## Pass or Fail Rows on Its Outputs

Under **Judgment Conditions**, add the condition `Support Style Check / score` ≥ 0.8. An answer that breaks any of the style rules scores below 0.8, so only one that follows all of them passes.

Custom and built-in metrics combine in the same conditions. Say the evaluation also scores the LLM node on Faithfulness. Add Faithfulness ≥ 0.8 too, and join the two conditions with AND.

## Update or Delete an Evaluator

* **Update its rules**: edit the evaluator and publish. The update applies to runs started afterward.

* **Delete it**: first make sure no run that uses it is in progress, since deleting cancels those runs. Deleting removes it from every evaluation that uses it, along with the conditions on its outputs. An evaluation that had no other metrics loses its whole saved setup.

## When the Evaluator Fails on a Row

A row usually shows `EVAL_CUSTOM_EVALUATOR_FAILED` for one of these reasons:

* **A mapped value is missing in that row**: the node it comes from didn't run, or didn't output the field you mapped. If a branch skipped the node, map from one that runs on every path instead.

* **A mapped value doesn't fit the evaluator's input variable**: for example, a value that isn't text, or text longer than the variable's length limit. The evaluator doesn't run, so nothing shows in its **Logs**. Check each mapping against its variable's type and length limit.

* **The evaluator's run failed**: for example, its model call errored. Find that run in the evaluator app's [**Logs**](https://enterprise-docs.dify.ai/en/3.14.x/use/monitor/logs.md) to see what went wrong.

* **The evaluator's creator has left the workspace**: the evaluator runs as the person who created it, so every row fails. Have a current member create a replacement, publish it as an evaluation workflow, and set it up in the evaluation in place of the old one.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.