Metadata-Version: 2.5
Name: payoff
Version: 0.1.0
Summary: Decide whether an AI system is worth using, and how much of its output people should check.
Project-URL: Homepage, https://github.com/ChristopherDaigle/payoff
Project-URL: Source, https://github.com/ChristopherDaigle/payoff
Project-URL: Issues, https://github.com/ChristopherDaigle/payoff/issues
Project-URL: Changelog, https://github.com/ChristopherDaigle/payoff/blob/main/CHANGELOG.md
Project-URL: Article, https://quantchris.com/posts/2026-11-29-is-it-possible-and-is-it-worth-it.html
Author: Christopher Daigle
License-Expression: MIT
License-File: LICENSE
Keywords: decision analysis,expected value,human in the loop,model evaluation,value of information
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# payoff

Decide whether an AI system is worth using, and how much of its output
people should check.

[![CI](https://github.com/ChristopherDaigle/payoff/actions/workflows/ci.yml/badge.svg)](https://github.com/ChristopherDaigle/payoff/actions/workflows/ci.yml)

Most AI work is funded on a model metric (accuracy, F1, AUC) and a business
case that assumes the model does all the work. Neither says whether the
*system* is worth having: the model, the cut-off someone chose, the people who
check some of its output, and the capacity they have. `payoff` prices every
outcome of that system, finds the best share of work to send to people, and
shows which uncertain inputs are worth measuring before you decide.

The name is the decision-theory term. Every way a decision can turn out has a
payoff, and the best design is the one with the highest expected payoff once
the model's errors, the reviewers' time, and the build are all counted.

It is the code companion to two articles:

- [Is It Possible, and Is It Worth It?](https://quantchris.com/posts/2026-11-29-is-it-possible-and-is-it-worth-it.html)
  covers what to do with the costs and benefits.
- [Where the Numbers Come From](https://quantchris.com/posts/2026-11-29-where-the-numbers-come-from.html)
  covers how to get them.

The same calculations are in a
[workbook](https://quantchris.com/assets/files/payoff-workbook.xlsx) for
readers who prefer a spreadsheet. The tests check that this package and the
workbook give the same numbers.

## Install

With [uv](https://docs.astral.sh/uv/):

```bash
uv add payoff
```

or with pip: `pip install payoff`.
Python 3.10 or later. No runtime dependencies.

## Quick start

```python
import payoff

# A refund team: 100,000 requests a year, dollars per request.
hourly = 50.0  # loaded cost per hour of a support rep
params = payoff.Params(
    value=10.0,  # a correct decision is worth what it costs to make today
    error_cost=50.0,  # a wrong decision that reaches a customer
    hand_cost=payoff.cost_of_minutes(12, hourly),
    confirm_cost=payoff.cost_of_minutes(3, hourly),
    fix_cost=payoff.cost_of_minutes(6, hourly),
    accuracy=0.80,
    separation=1.5,
    catch_rate=0.90,
    overturn_rate=0.02,
    capacity=0.40,
    run_cost=0.50,
)

best = payoff.best_within_capacity(params)
best.share_reviewed  # 0.40: check 40% of requests
payoff.advantage(params)  # 4.81: dollars saved per request versus today
payoff.payback_months(200_000, payoff.advantage(params) * 100_000)  # 5.0
```

`examples/quickstart.py` adds sensitivity, simulation, and the value of
measuring each input:

```text
$ uv run python examples/quickstart.py
Check 40% of items.
Advantage over doing it by hand: $4.81 per item,
  $480,911 per year.
Pays back the build 5.0 months after launch, 9.0 after funding.
One more point of capacity is worth $4,375 per year.

What to measure first (advantage per year, low to high):
  error_cost       $646,782 to  -$348,443  <- can change the answer
  hand_cost        $230,911 to   $730,911
  ...
Beats the current process in 66% of 2,000 draws.
  Knowing error_cost exactly is worth about $71,054 per year.
```

## What it answers

| Question | Function |
|---|---|
| What is each design worth per item? | `expected_value_by_hand`, `expected_value_full_automation`, `expected_value_review_all`, `evaluate` |
| What accuracy does each design need? | `break_even_accuracy_full_automation`, `break_even_accuracy_review_all` |
| What share should people check, given their capacity? | `best_within_capacity`, `advantage` |
| What is more review capacity worth? | `capacity_value` |
| When does the build pay back, and what is it worth over its life? | `payback_months`, `net_value` |
| Which inputs could change the answer? | `Range`, `sensitivity` |
| How likely is the system to beat the current process? | `simulate` |
| Which measurement is worth paying for? | `value_of_information` |
| What are reviewers' catch and overturn rates? | `beta_posterior_mean`, `wilson_interval`, `seeded_errors_needed` |
| What error rate do the edits imply? | `implied_error_rate` |
| The numbers say no: proceed, wait, or stop? | `decide` |

Every public function has a docstring with its arguments and return value.

## The model

Each item gets a confidence score. Items at or above a cut-off go straight
through; the rest go to a person, up to the review capacity. A person
confirms a correct draft, fixes a wrong one they catch, misses the rest, and
now and then changes a correct draft into a wrong one.

| Input | Meaning |
|---|---|
| `value` | Value of one correct result |
| `error_cost` | Cost of an error that gets through, on top of the value lost |
| `hand_cost` | Cost of doing one item from scratch |
| `confirm_cost`, `fix_cost` | Cost of confirming a correct draft, fixing a wrong one |
| `accuracy` | Share of outputs that are right |
| `separation` | How well the score tells right from wrong, in standard deviations |
| `catch_rate` | Share of wrong drafts people catch |
| `overturn_rate` | Share of correct drafts people change to wrong |
| `capacity` | Share of items people can check |
| `run_cost` | Cost of running the system, per item |

Money inputs can be in any one unit. The articles, the workbook, and these
examples use dollars, with a refund team as the running example. Setting
`value=1` instead measures everything relative to the value of a correct
result, which is handy for comparing very different systems.

Assumptions, stated so you can judge whether they fit:

- Scores are normal with unit variance: mean `separation` for correct
  outputs, mean 0 for wrong ones. Calibrate against your own score
  distributions before relying on the routing result.
- One error cost per item. Systems with several kinds of error should price
  them separately and use a weighted average, or extend the model.
- Reviewers' catch and overturn rates do not depend on the cut-off. In
  practice they move when the review queue changes; the articles explain how
  to measure them per queue.

## How it matches the workbook

`best_within_capacity` searches a grid of cut-offs and then checks the
cut-off that fills capacity exactly, found by bisection. The workbook does the
same with formulas (201 cut-offs, 60 bisection steps).
`tests/test_workbook.py` reads the workbook's computed values and recomputes
each one from its inputs.

## Project layout

```text
src/payoff/
  model.py        outcomes, routing, break-even, capacity value, payback
  measure.py      ranges, sensitivity, simulation, reviewer statistics
  discretion.py   proceed, wait, or stop
tests/
  test_model.py       properties that hold for any inputs
  test_measure.py     measurement helpers
  test_workbook.py    parity with the published workbook
  test_repo.py        every text file is plain ASCII
  data/payoff-workbook.xlsx
examples/quickstart.py
```

## Development

```bash
uv sync                    # creates .venv from uv.lock
uv run pytest              # tests
uv run ruff check          # lint (Google docstring convention)
uv run ruff format --check # formatting
uv run mypy                # strict type checks
```

CI runs all four on Python 3.10 to 3.13. Releases go to PyPI from a version
tag; see [RELEASING.md](RELEASING.md).

## Design choices

- **No runtime dependencies.** The math needs only the standard library, so
  there is nothing to audit or pin for users.
- **Frozen dataclasses with validation.** Bad inputs fail when they are
  created, with a message naming the field.
- **Repeatable randomness.** `simulate` takes a seed and defaults to 0.
- **Plain text.** A test keeps every text file ASCII, so nothing renders
  differently from one terminal or editor to the next.

## Roadmap

The articles climb a ladder, and the package will follow it:

1. A classic model: two kinds of error, thresholds from costs, ranking under
   fixed capacity.
2. Extraction: many fields per document and many documents per case, where
   correctness compounds.
3. AI agents: a sequence of steps that take actions, with approval at
   irreversible ones.
4. Several AI agents: handoffs, and AI agents checking each other.

## Citing

See `CITATION.cff`, or use GitHub's "Cite this repository" button.

## License

MIT. See `LICENSE`.
