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

> ## Agent Instructions
> Read the relevant procedure and prerequisites before suggesting commands. Cite the section and give an observable check. Treat sample data as illustrative. Report product actions and results only when verified in the user's environment.

# Configure custom diagnosers

> Turn a check into a rule or LLM instruction and validate it against real traces.

Create a custom diagnoser when the existing checks cannot express your requirement. For built-in rules and specialist trials that require no prompt or Python, see [Start with existing diagnosers](https://aivision.mintlify.site/en/guides/use-diagnosers.md).

Creating custom diagnosers is available to team-space administrators and developers. Personal spaces use platform-provided built-in capabilities.

## Start with existing checks

First consult the [existing diagnoser catalog](https://aivision.mintlify.site/en/guides/use-diagnosers.md#1-find-an-applicable-existing-check) before deciding to create a custom check. Rules suit explicit fields and conditions. LLM checks suit semantic questions requiring context and need an available [model connection](https://aivision.mintlify.site/en/guides/model-connections.md).

## Try a specialist check for an explicit requirement

Answer relevance, follow-up reasonableness, numeric consistency, response language, and protected markers have an independent specialist entry. Follow the [specialist trial steps](https://aivision.mintlify.site/en/guides/use-diagnosers.md#2-try-one-explicit-requirement-independently) with one Trace before deciding whether to save the configuration and add it to a team task.

## Configure a custom rule

For isolated execution, first configure a connection and Space policy using the [Sandbox guide](https://aivision.mintlify.site/en/guides/sandbox.md), then choose the execution mode in the rule form. Sandbox is optional: without a selected connection or a Space requirement, local execution remains available for restricted rules. Enhanced Python requires a compatible sandbox.

Use the form's “output exists” example to practice the complete workflow:

1. In a team space, select **Diagnosers → New diagnoser**, choose the rule type, and enter a name, category, and scenario.
2. Select **View Trace Structure** and choose or enter a real Trace ID whose Agent output you have already confirmed. Find that output field under `spans`.
3. Copy the generated Python expression and replace the empty string on the right of `output = ""` in the example. The unchanged example returns `bad`; do not save it for batch checks without this replacement.
4. Keep the declared metric and returned name aligned as `quality`. Under **Test and Validate**, select the same Trace and choose **Run Diagnosis**. Compare the valid verdict, reason, and `output_length` evidence with the original content. Resolve missing samples, missing fields, or execution failures first.
5. Test the `bad` branch with a sample whose output field exists but is confirmed empty, then select **Create**. Return to the diagnoser list and confirm the configuration appears.

This example verifies field access and rule execution, not answer correctness or task completion. The current entry point is `evaluate(trace)`, with raw spans available through `trace.spans`. Arbitrary `import` statements are not supported.

Declare unique metric names in the editor. The returned object's `metrics` array must contain exactly one entry per declared metric:

| Field | Requirement |
| - | - |
| `name` | Matches a declared metric name. |
| `verdict` | `good` or `bad`; the platform records execution failures. |
| `reason` | A string explaining the judgment; `bad` requires a non-empty reason. |
| `evidence` | Optional. When provided, it must be a JSON object, such as `{"span_id": "..."}`, rather than a string or array. |

### Complete rule template

The following shows the complete result shape from the [current form example](https://github.com/ob-labs/ai-vision-ob/blob/b0908e84288fc0e189badd8a36e40e92a2497197/ai-vision/vfe/src/components/diagnose/diagnoser/CreateRuleDiagnoserForm.tsx#L55). **This is a template that still needs a real field expression, not a finished diagnosis rule.** First declare one metric named `quality` in the editor and copy an expression from a real Trace as described above.

```python theme={null}
def evaluate(trace):
    # REQUIRED: replace with the real field expression from View Trace Structure
    output = ""
    output = str(output or "").strip()
    if not output:
        return {
            "metrics": [{
                "name": "quality",
                "verdict": "bad",
                "reason": "Agent produced no output",
                "evidence": {},
            }]
        }
    return {
        "metrics": [{
            "name": "quality",
            "verdict": "good",
            "reason": "Agent produced output",
            "evidence": {"output_length": len(output)},
        }]
    }
```

The unchanged `output = ""` always returns `bad`. If the field is absent, the wrong field is selected, or Privacy masks the content, resolve the material and applicability first. Missing data does not prove that the Agent actually produced empty output. Once the field is confirmed to represent the intended output, validate both branches with one non-empty sample and one confirmed empty sample.

Do not reuse an older rule that returns only a score between 0 and 1. Trial the rule on a known good example and a confirmed problem, including missing fields, retries, and long executions.

If a trial reports invalid metric names or result formatting, first match the declared `metrics[].name` values to the returned entries, then check the shape of `reason` and `evidence`. This is an execution-contract error, not evidence of poor Agent quality.

## Configure a custom LLM diagnoser

**1. State what you need to verify**

In a team space, open **Diagnosis → Diagnosers → New Diagnoser** and choose LLM. Define the subject, what counts as a problem, and the evidence the check should cite. For example, to detect a claim of success after a tool failure, compare the final answer with the original tool result and check whether a later retry succeeded.

**2. Select fields from a real Trace**

Under **Diagnosis Logic**, select **View Trace Structure**. Open a sample you have already examined. Under **Select span**, find the request root and the relevant tool span. Choose a recorded input or output field and use **Expression and value → Evaluate** to check its value before copying the expression. Distinguish the request, the visible final answer, and intermediate tool results. Field names vary by Agent and collection method. If the value is empty, check the original Trace.

**3. Verify the field against a second sample**

Copy the expression you want to reuse, then select another Trace or enter its ID in the structure dialog. Switching samples resets field selection. Enter the same path under **Expression** and select **Evaluate** again. Once both samples contain the expected material, use **Copy** to copy the double-brace expression into **Diagnosis Logic**. The actual value replaces the expression at runtime.

**4. Choose a judge model and test two outcomes**

Under **Runtime Model**, select a connection in this space that passed **Diagnostic validation**. Use **Manage Connections** to configure and validate a connection in place, then close the dialog to continue editing the draft. Under **Test and Validate**, select a reference Trace and choose **Run Diagnosis**. Check the verdict, reason, and evidence, then run a second Trace with a different expected result. Each trial uses the selected Trace and current draft.

<video controls playsInline preload="none" poster="/assets/walkthrough/en/llm-field-preview.webp" src="https://mintcdn.com/aivision/ZEwXG9qC_6SHqrLa/assets/walkthrough/en/llm-field-preview.mp4?fit=max&auto=format&n=ZEwXG9qC_6SHqrLa&q=85&s=f90fc80d18943d6c2de553a30017de37" aria-label="Switch the sample and evaluate an output field in the Trace structure dialog">
  The video switches to a new sample and reads its output field on the request root.
</video>

Switch samples, find the output on the request root, and evaluate the field value. Demo data, Chinese interface.

The video searches **Select field** for `attributes.langfuse.observation.output`, enters an expression for that field, and selects **Evaluate**. The highlight shows the sample answer, and the counter shows one matching value. Confirm that your selected field contains the evidence you need, then run **Test and Validate**. Use the field recorded by your collection method.

Save the diagnoser to persist its model and instructions. The connection is shared within the space, while the prompt and generation settings belong to the diagnoser. Basic diagnostic validation cannot substitute for testing against a real Trace.

## Verify after saving

Confirm the configuration appears in the list. To produce a result you can revisit, open **Agent Traces → Run diagnosis → Saved diagnosers**, select the saved configuration, run it, then select **View quality results**. To repeat the check over a fixed scope, add it to a [diagnosis task](https://aivision.mintlify.site/en/guides/diagnosis-tasks.md) and confirm execution in its history.

Run another trial after changing the reference Trace, instructions, or model. Changes affect subsequent execution; compare historical results with their original configuration and data scope. For checks requiring original content, inspect applicability and missing evidence when using Privacy data. Failure or skipping does not mean the task had no problem.


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