# undetermini

> Eval harness for non-deterministic (LLM) code — subjects, variants (provider × model × reasoning), weighted-assertion scoring, trial cache, SQLite runs, CLI + TUI.

Latest version **0.4.2** (published 2026-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install undetermini
pnpm add undetermini
yarn add undetermini
bun add undetermini
```

Provides the commands `undetermini`, `undetermini-tui`.

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2026-10-14 |
| First published | 2023-10-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 9 |
| Unpacked size | 1.8 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | Sraleik |
| Maintainers | sraleik |
| Keywords | llm, eval, testing, non-deterministic, prompt-engineering |

## Links

- npm: https://www.npmjs.com/package/undetermini
- Repository: https://github.com/Sraleik/undetermini
- Homepage: https://github.com/Sraleik/undetermini#readme
- Issues: https://github.com/Sraleik/undetermini/issues
- npm.io page: https://npm.io/package/undetermini

## Dependencies (9)

- [ai](https://npm.io/package/ai.md) ^6.0.116
- [ink](https://npm.io/package/ink.md) ^5.2.1
- [tsx](https://npm.io/package/tsx.md) ^4.7.0
- [react](https://npm.io/package/react.md) ^18.2.0
- [dotenv](https://npm.io/package/dotenv.md) ^16.3.1
- [p-limit](https://npm.io/package/p-limit.md) ^5.0.0
- [@ai-sdk/openai](https://npm.io/package/@ai-sdk/openai.md) ^3.0.41
- [better-sqlite3](https://npm.io/package/better-sqlite3.md) ^13.0.3
- [@ai-sdk/provider](https://npm.io/package/@ai-sdk/provider.md) ^3.0.8

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 0.4.2 (latest) — 2026-10-14
- 0.4.1 — 2026-10-08
- 0.4.0 — 2026-10-08
- 0.3.1 — 2026-09-16
- 0.3.0 — 2026-08-10
- 0.2.4 — 2026-07-09
- 0.1.3 — 2024-05-04
- 0.1.2 — 2024-05-04
- 0.1.1 — 2024-05-02
- 0.1.0 — 2023-11-09
- 0.0.9 — 2023-11-07
- 0.0.8 — 2023-11-07
- 0.0.7 — 2023-10-30
- 0.0.6 — 2023-10-27
- 0.0.5 — 2023-10-26
- … 4 more at https://npm.io/package/undetermini/versions

## README

# undetermini

An eval harness for **non-deterministic code** — the kind whose output you
can't assert with `===` because it comes from an LLM (sampling, ranking,
classification, extraction…).

<p align="center">
  <img src="./assets/tui-example.png" width="820" alt="undetermini TUI — variants compared across score, pass-rate, cost and latency" />
  <br/>
  <em>The <code>npm run eval:tui</code> results grid: variants (model × system-prompt × reasoning) ranked by score, with cost, latency and cache hits.</em>
</p>

You define a **subject** (the code under test), declare **variants**
(provider × model × reasoning), run them across **cases** for **N trials
each**, and score every trial with **weighted assertions**. Results persist to
SQLite so you can diff runs and catch statistical regressions when you swap a
model or edit a prompt.

> This is generation 2. It grew inside a production codebase (a talent-search
> NL filter) and was extracted here to stand on its own. The original library
> (`Undetermini` / `UsecaseImplementation`) is preserved under [`legacy/`](./legacy).

---

## Unit test vs eval

|                          | **Unit test**        | **Eval**                                            |
| ------------------------ | -------------------- | --------------------------------------------------- |
| Input → output           | deterministic        | **non-deterministic** (LLM, sampling, ranking…)     |
| Pass criterion           | binary (`=== expected`) | **distribution** (pass-rate over N trials, threshold) |
| Catches                  | logic bugs           | **statistical regressions** (model swap, prompt drift) |

A unit test asks *"does this function compute X correctly?"*. An eval asks
*"does this LLM-driven feature behave correctly **most of the time**?"*.

---

## Requirements

- **Node ≥ 22** (native `better-sqlite3`).
- An `.env` with the provider keys you intend to run, e.g. `OPENAI_API_KEY`
  (and `ANTHROPIC_API_KEY` for Anthropic variants). Only needed for real runs —
  the test suite and typecheck need nothing.

---

## Use it in your project

```bash
npm install undetermini
```

Declare what you want to evaluate in an `undetermini.config.ts` at the root of
your project. The binaries find it by walking up from wherever you run them, the
way vitest finds `vitest.config.ts`:

```ts
// undetermini.config.ts
import { defineConfig } from 'undetermini';
import { mySubject } from './eval/my-subject';

export default defineConfig({
  subjects: {
    'my-subject': {
      subject: mySubject,
      evalFile: 'eval/my-subject.ts',
      casesDir: 'eval/cases',
      promptsDir: 'eval/prompts',
      prompts: [],
      schemas: [],
    },
  },
  defaultSubject: 'my-subject',
});
```

That is all the wiring there is. Two commands ship with the package:

| Command                    | What it does                                              |
| -------------------------- | --------------------------------------------------------- |
| `undetermini`              | Run the eval from the command line.                        |
| `undetermini-tui`          | Same runs, interactive: pick axes, watch trials live.      |

```bash
npx undetermini --subject=my-subject --case-slugs=some-case --trial-count=5
npx undetermini --config ./path/to/undetermini.config.ts   # bypass discovery
```

Run either one with no config in sight and it tells you how to write one — it
will not start billed trials on its own. To watch the harness work on its
built-in subject, ask for it: `npx undetermini --subject=example` (that one
calls a real model).

Both binaries read the `.env` sitting at your project root, after moving there.
**Importing the library does not**: if you write your own entry point that calls
the runners, loading the environment is yours to do.

### Calling it from your own code

```ts
import { EvalEngine, openEvalDb } from 'undetermini';          // the engine
import { runEvalCli, runEvalTui } from 'undetermini/clients';  // the two clients
```

The clients live at `undetermini/clients` and that subpath is ESM-only — the TUI
depends on `ink`, whose top-level await cannot be `require`d. The main entry
point works in both ESM and CommonJS.

---

## Working in this repo

```bash
npm install
```

## Commands

| Command                | What it does                                                        |
| ---------------------- | ------------------------------------------------------------------- |
| `npm run eval`         | Run the CLI harness (default subject: `example`).                   |
| `npm run eval:tui`     | Interactive Ink TUI — pick axes, watch trials, sort/aggregate live. |
| `npm run rescore`      | Retroactively re-score stored trials against the current cases.     |
| `npm test`             | `vitest` unit suite (157 tests, no network).                        |
| `npm run typecheck`    | `tsc --noEmit`.                                                     |
| `npm run build:docs`   | Generate API docs into `./docs` via typedoc.                        |

Pick a subject and narrow cases:

```bash
npm run eval -- --subject=example --case-slugs=clearly-positive --trials=5
```

## Layout

```
src/
├── index.ts                  ← public API barrel (typedoc entry point)
├── engine/                   ← the generic harness — never imports a subject
│   ├── api.ts                  EvalEngine (event-emitting run driver)
│   ├── runner-loop.ts          cases × variants × trials (p-limit)
│   ├── variant.ts              EvalVariant (provider × model × reasoning)
│   ├── scorers.ts              weighted caseAssertionsScorer
│   ├── axes/                   cartesian variant expansion + capability matrix
│   ├── cache/                  trial-aware LLM cache (SQLite-backed)
│   ├── storage/                schema, writers, fingerprint
│   ├── rescore/                retroactive rescore
│   ├── pricing.ts              $/1M-token table
│   └── telemetry-middleware.ts token + latency capture
├── config.ts                 ← undetermini.config.ts discovery + defineConfig
├── clients/
│   ├── index.ts                `undetermini/clients` — the two runners
│   ├── cli/                    `undetermini` binary, console printer
│   └── tui/                    `undetermini-tui` binary (pages, store, prefs)
├── subjects/
│   ├── registry.ts            the registry contract + the reference registry
│   └── example-sentiment/     reference subject (inline cases, no I/O)
└── shared/                    cross-cutting types
```

Design notes live at the repo root: [`VARIANT-AXES-DESIGN.md`](./VARIANT-AXES-DESIGN.md),
[`INTERACTIVE-VARIANT-DESIGN.md`](./INTERACTIVE-VARIANT-DESIGN.md),
[`LLM-CALL-OPTIMIZATION-DESIGN.md`](./LLM-CALL-OPTIMIZATION-DESIGN.md),
[`SCORER-ASYMMETRY-DESIGN.md`](./SCORER-ASYMMETRY-DESIGN.md),
[`PRICING.md`](./PRICING.md), [`ONBOARDING.md`](./ONBOARDING.md).

---

## Adding a subject

A subject is anything implementing the `Subject` contract (`src/engine/runner-loop.ts`):
`name`, `cases`, `variants`, `runOne`, `parse`. See
[`src/subjects/example-sentiment`](./src/subjects/example-sentiment) for a
complete, dependency-free reference.

Then register it — one entry in your `undetermini.config.ts`, no runner edits:

```ts
export default defineConfig({
  subjects: {
    'my-thing': { subject: myThingSubject, evalFile, casesDir, promptsDir },
  },
  defaultSubject: 'my-thing',
});
```

The registry is the composition root and it belongs to **your** project, not to
the harness: naming concrete subjects is the one thing a generic eval library
cannot do for you. Runners resolve through `resolveIn(registry, name)`, so a new
use case never touches the CLI, the TUI, or the engine.

---

## Concepts

- **Subject** — the code under test + its cases + its variants.
- **Variant** (`EvalVariant`) — one LLM configuration: provider (`openai` /
  `anthropic`), `modelId`, and the provider-specific reasoning knob
  (`reasoningEffort` / `thinkingBudgetTokens`), plus an optional `systemPrompt`
  override hashed into the variant's identity.
- **Case** — one input plus its weighted `assertions` (the *contract*: what the
  output must express, by category).
- **Trial** — one (variant × case) execution. N trials per pair measure
  stability, not one-shot luck.
- **Score** — weighted pass-rate ∈ [0,1] per trial, aggregated per variant.

---

## License

MIT — see [`LICENSE.txt`](./LICENSE.txt).

---
_Source: https://npm.io/package/undetermini · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
