# Check handoff rules

<!-- BEGIN GENERATED: usage -->

Decide whether a request matches your human escalation rules.

Use when: You need to decide whether your escalation rules call for a human.

Install `jev-recipes` and set `TYPESAFE_API_KEY` in your server environment. See the [quick start](https://github.com/agencyenterprise/jev-recipes/blob/main/README.md#use-a-recipe).

```ts
import { handoff } from 'jev-recipes/handoff';

const result = await handoff({
  request: 'Please connect me with a person.',
  rules: [
    {
      id: 'requested-human',
      description: 'The customer explicitly asks to speak with a human support representative.',
    },
  ],
});
console.log(result);
```

Try the saved example without an API key: `npx jev-recipes demo handoff`.

<details>
<summary>Illustrative result from the offline fixture</summary>

```json
{
  "model": "demo-fixture",
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0
  },
  "status": "ready",
  "decision": "human",
  "matchedRules": ["requested-human"],
  "uncertainRules": [],
  "checks": [
    {
      "id": "requested-human",
      "status": "ready",
      "verdict": "matches",
      "confidence": 0.96,
      "probabilities": {
        "matches": 0.97,
        "does_not_match": 0.015,
        "unclear": 0.015
      }
    }
  ]
}
```

This saved response illustrates behavior; it is not a model accuracy measurement.

</details>

Related recipes:

- [`route`](https://jev-recipes.com/recipes/route/): Use route to choose a handler when escalation is not the decision.

<!-- END GENERATED: usage -->

## Input

<!-- BEGIN GENERATED: input -->

| Field           | Required | Shape                                                     |
| --------------- | -------- | --------------------------------------------------------- |
| `request`       | Yes      | string                                                    |
| `context`       | No       | string                                                    |
| `rules`         | Yes      | { id, description }[]; at least 1 items; at most 50 items |
| `minConfidence` | No       | number; minimum 0; maximum 1                              |

This table is generated from the input schema. Additional text, uniqueness, and policy checks are described below and in the shared options.

<!-- END GENERATED: input -->

See [shared options and behavior](https://github.com/agencyenterprise/jev-recipes/blob/main/recipes/README.md#shared-options-and-behavior) for client configuration, validation, and errors. Types are inferred from this folder's Zod 4 schemas.

## Result

| Decision   | Condition                                                                                     |
| ---------- | --------------------------------------------------------------------------------------------- |
| `human`    | At least one rule confidently matches.                                                        |
| `review`   | No confident match exists and at least one rule is unclear or below the confidence threshold. |
| `continue` | Every rule confidently does not match.                                                        |

`checks` preserves each rule ID with its verdict (`matches`, `does_not_match`, or `unclear`), status, confidence, and probabilities. Check status reflects the confidence threshold. A high-confidence `unclear` verdict still describes uncertainty about whether the rule applies.

`matchedRules` contains confident matches. `uncertainRules` contains unclear and low-confidence checks. One confident match is enough for `decision: "human"` and `status: "ready"`, even when other rules are uncertain. A review decision always has review status.

The result includes model and token usage. Inspect the outcome as well as its review status.

## Reuse and calls

Uses the shared item-check helper. This folder owns the rule criteria and human, continue, or review decision. All rule questions are sent in one request. A live invocation makes one logical Jev request; SDK retries can add transport attempts.

## Limits

Write observable rules and supply the facts needed to evaluate them. Compute exact amounts, deadlines, and permissions in code. This recipe does not contact anyone, execute actions, or enforce access controls.

## Example input

[demo.json](https://github.com/agencyenterprise/jev-recipes/blob/main/recipes/handoff/demo.json) contains editable input and a hand-authored response. After installing `jev-recipes`, `npx jev-recipes demo handoff` shows an offline illustration, not an accuracy measurement. Use `npx jev-recipes describe handoff` to inspect the input and result schemas.

## Measured accuracy

<!-- BEGIN GENERATED: accuracy -->

**Current synthetic measurement; experimental.**

Measured on 60 golden cases against `jev-1.13.0`: **92% accurate** overall (contested cases 67%, adversarial cases 100%).

Recorded 2026-10-04 with package 0.9.12, on the **development** split. Recipe fingerprint: `a6b4ea63f7fd7fa621bad8ebdac68421b2db9ccbf35efc7fd32ca34bc4f712c5`.

Scoring revision: 2.

55/60 cases correct; 47 ready, 13 review, 0 failed. Accuracy among ready cases: 96%.

Latency: p50 106.78 ms, p95 146.17 ms. Usage: 28423 input tokens and 2660 output tokens across 60 logical requests.

Labels: author-synthetic (60 cases): AI-authored synthetic boundary cases for jev-recipes; labels have not had independent human review.

These authored cases are not independent human validation. Related variants are correlated; case-level confidence intervals can overstate independent evidence.

95% case-level accuracy interval: 82% to 96%.

| `minConfidence` | Deferred to review | Accuracy of ready results |
| --------------- | ------------------ | ------------------------- |
| 0.5             | 18%                | 92%                       |
| 0.6             | 18%                | 92%                       |
| 0.7             | 22%                | 96%                       |
| 0.8             | 22%                | 96%                       |
| 0.9             | 27%                | 96%                       |
| 0.95            | 33%                | 100%                      |

The lowest threshold reaching 95% accuracy on ready results is 0.65.

Run `npm run eval -- handoff` to save new results and update this guide. The full report, including misses, is in [evals/results/handoff.json](https://github.com/agencyenterprise/jev-recipes/blob/main/evals/results/handoff.json). Accuracy on your own data may differ.

<!-- END GENERATED: accuracy -->

Canonical guide: https://jev-recipes.com/recipes/handoff/
Evidence: Current synthetic measurement. Last updated 2026-10-04.
