# Grade extraction fidelity

<!-- BEGIN GENERATED: usage -->

How faithfully does extracted represent the facts in source, without invented, altered, or dropped values, on a five-level rubric?

Use when: You need to grade a structured extraction against its source document before trusting, storing, or acting on the values.

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 { extractionFidelity } from 'jev-recipes/extraction-fidelity';

const result = await extractionFidelity({
  source:
    'Invoice INV-2041 issued 3 March 2026 to Harbor Lighting Ltd for 12 LED fixtures at $85.00 each. Subtotal $1,020.00, tax $81.60, total $1,101.60. Payment due 2 April 2026.',
  extracted:
    '{"invoiceNumber":"INV-2041","issued":"2026-03-03","customer":"Harbor Lighting Ltd","total":1101.6,"due":"2026-04-02"}',
  minConfidence: 0.8,
});
console.log(result);
```

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

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

```json
{
  "model": "demo-fixture",
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0
  },
  "status": "ready",
  "score": 3.04,
  "level": 3,
  "confidence": 0.81,
  "probabilities": {
    "0": 0,
    "1": 0.01,
    "2": 0.06,
    "3": 0.81,
    "4": 0.12
  },
  "fidelity": "high"
}
```

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

</details>

Related recipes:

- [`field-select`](https://jev-recipes.com/recipes/field-select/): Use field-select to pick which field a value belongs to before grading the result.
- [`summary-coverage`](https://jev-recipes.com/recipes/summary-coverage/): Use summary-coverage when the output is prose that should cover the source, not a set of fields.

<!-- END GENERATED: usage -->

## Input

<!-- BEGIN GENERATED: input -->

| Field           | Required | Shape                        |
| --------------- | -------- | ---------------------------- |
| `source`        | Yes      | string                       |
| `extracted`     | Yes      | string                       |
| `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. `extracted` is a string; pass the output of `JSON.stringify` for a structured record.

## Result

`fidelity` is one of `poor`, `low`, `fair`, `high`, or `exact`, taken from the most likely rubric level. `level` is that level's index from 0 to 4. `score` is Jev's expected value across the rubric and can fall between levels; use it to rank extractions or set an acceptance threshold.

A result is `ready` when `confidence` meets `minConfidence`. Otherwise it is `review` and still carries the graded values for inspection. `probabilities` is keyed by level index.

## Reuse and calls

Uses the shared score helper. This folder owns the fidelity question, the rubric wording, and the review policy. A live invocation makes one logical Jev request.

## Limits

The rubric grades agreement between `extracted` and `source`. It does not check whether the source is accurate or current, and it does not know your schema, so a field the extractor was never asked for counts as an omission only when the source states it. The grade is a single number for the whole extraction; it does not say which value is wrong or missing. Add a per-field check when you need to correct specific values.

## Example input

[demo.json](https://github.com/agencyenterprise/jev-recipes/blob/main/recipes/extraction-fidelity/demo.json) contains editable input and a hand-authored response. After installing `jev-recipes`, `npx jev-recipes demo extraction-fidelity` shows an offline illustration, not an accuracy measurement. Use `npx jev-recipes describe extraction-fidelity` 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`: **100% accurate** overall (contested cases 100%).

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

Scoring revision: 2.

60/60 cases correct; 60 ready, 0 review, 0 failed. Accuracy among ready cases: 100%.

Latency: p50 103.09 ms, p95 170.2 ms. Usage: 36535 input tokens and 1020 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: 94% to 100%.

| `minConfidence` | Deferred to review | Accuracy of ready results |
| --------------- | ------------------ | ------------------------- |
| 0.5             | 0%                 | 100%                      |
| 0.6             | 0%                 | 100%                      |
| 0.7             | 0%                 | 100%                      |
| 0.8             | 0%                 | 100%                      |
| 0.9             | 0%                 | 100%                      |
| 0.95            | 5%                 | 100%                      |

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

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

<!-- END GENERATED: accuracy -->

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