# Eval Compare

> Versions of a prompt or model on the same test cases, side by side, with pass rates, scores, latency and a verdict per case.

Page: https://uicontext.com/docs/components/eval-compare

Group: Agents.

## When to use

Versions of a prompt or model on the same test cases, side by side, with pass rates, scores, latency and a verdict per case. Use [Trace View](https://uicontext.com/docs/components/trace-view.md) instead when you're looking into one run, not comparing versions across cases.

## Usage

```ts
import { EvalCompare, type EvalCase, type Verdicts } from "./ui/uicontext/components/EvalCompare.ts"

export const PromptCompare = <M>(h: Html.H<M>, cases: ReadonlyArray<EvalCase>, verdicts: Verdicts, onJudge: (verdicts: Verdicts) => M) =>
	EvalCompare(h, {
		props: {
			label: "Prompt v7 against v8",
			variants: [{ id: "v7", name: "Prompt v7" }, { id: "v8", name: "Prompt v8" }],
			cases,
			value: verdicts,
		},
		onEmit: { RequestedChange: ({ value }) => onJudge(value) },
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### Reviewing a prompt change

The example the page opens with: Eval Compare in “Reviewing a prompt change”.

```ts title="src/demo.ts" source="www/src/examples/eval-compare/demo.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { EvalCompare, type EvalCase, type EvalVariant } from "./ui/uicontext/components/EvalCompare.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({ wrap: { inlineSize: "100%" } })

const variants: ReadonlyArray<EvalVariant> = [
	{ id: "v7", name: "Prompt v7", detail: "current, in production" },
	{ id: "v8", name: "Prompt v8", detail: "adds the refund policy and two examples" },
]

const cases: ReadonlyArray<EvalCase> = [
	{
		id: "refund-late",
		input: "My order arrived 9 days late and the mug was chipped. I want my money back.",
		expected: "Apologize, offer a replacement or refund for the mug, no refund on shipping past 30 days.",
		outputs: {
			v7: { text: "So sorry about that! I've refunded your whole order, including shipping.", pass: false, score: 0.41, latencyMs: 1820, reason: "Refunded more than the policy allows" },
			v8: { text: "I'm sorry the mug arrived chipped and late. I can send a new one today or refund the $24 for it. Which would you prefer?", pass: true, score: 0.92, latencyMs: 2140 },
		},
	},
	{
		id: "address-change",
		input: "Can I change the address on order 51207? I moved last week.",
		expected: "Ask for the new address; say it can change until the order ships.",
		outputs: {
			v7: { text: "Sure. What's the new address? I can update it until the order ships.", pass: true, score: 0.88, latencyMs: 1210 },
			v8: { text: "Of course. Send me the new address and I'll update order 51207. Changes work until it ships, usually within a day.", pass: true, score: 0.9, latencyMs: 1460 },
		},
	},
	{
		id: "angry-caps",
		input: "THIRD TIME ASKING. WHERE IS MY PACKAGE",
		expected: "Stay calm, apologize once, give tracking and a date.",
		outputs: {
			v7: { text: "I understand your frustration. Your package is on its way.", pass: false, score: 0.35, latencyMs: 980, reason: "No tracking link or date" },
			v8: { text: "I'm sorry you've had to ask three times. It's with the courier, arriving Thursday: track it at the link below.", pass: true, score: 0.86, latencyMs: 1630 },
		},
	},
	{
		id: "wholesale",
		input: "Do you sell wholesale? We run a café and want 200 mugs.",
		outputs: {
			v7: { text: "Yes! For orders over 100 we offer 20% off. Want me to start a quote?", pass: true, score: 0.8, latencyMs: 1100 },
			v8: { text: "We do. I'll pass this to our wholesale team; they reply within a day with pricing for 200 mugs.", pass: true, score: 0.84, latencyMs: 1390 },
		},
	},
	{
		id: "competitor-price",
		input: "I saw the same tote cheaper somewhere else. Will you match it?",
		expected: "Don't promise a match; explain the policy politely.",
		outputs: {
			v7: { text: "We don't match prices, but here's 10% off your next order.", pass: false, score: 0.52, latencyMs: 1040, reason: "Offered a discount it can't give" },
			v8: { text: "We don't match other shops' prices, sorry. If the price drops here within 14 days, we'll refund the difference.", pass: false, score: 0.66, latencyMs: 1720, reason: "Price drop policy is 7 days, not 14" },
		},
	},
	{
		id: "german",
		input: "Hallo, wann kommt meine Bestellung an?",
		expected: "Answer in German.",
		outputs: {
			v7: { text: "Hallo! Ihre Bestellung ist unterwegs und kommt voraussichtlich am Freitag an.", pass: true, score: 0.9, latencyMs: 1150 },
			v8: { text: "Hello! Your order should arrive on Friday.", pass: false, score: 0.3, latencyMs: 1310, reason: "Replied in English" },
		},
	},
]

const Message = UiSchema.TaggedEnum({ Judged: { verdicts: Schema.Record(Schema.String, Schema.String) } })

// a review of a prompt change before it ships: v8 fixes refunds, but breaks replies in German
export const PromptReview = Html.component({
	name: "PromptReview",
	model: Schema.Struct({ verdicts: Schema.Record(Schema.String, Schema.String) }),
	message: Message,
}).make({
	init: () => ({ verdicts: { "refund-late": "v8", "address-change": "tie" } }),
	update: { Judged: ($, { verdicts }) => $.evolve({ verdicts }) },
	view: (h, model) =>
		h.div.attrs(sx(styles.wrap)).children(
			EvalCompare(h, {
				key: "review",
				props: { label: "Support replies: prompt v7 against v8", variants, cases, value: model.verdicts },
				onEmit: { RequestedChange: ({ value }) => Message.Judged({ verdicts: value }) },
			}),
		),
})
```

### Three at once

Scores without pass/fail checks: the head compares mean score and latency, and Medium matches Large at a third of the wait.

```ts title="src/models.ts" source="www/src/examples/eval-compare/models.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { EvalCompare, type EvalCase } from "./ui/uicontext/components/EvalCompare.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({ wrap: { inlineSize: "100%" } })

// three model sizes pulling fields out of invoices, scored by a grader with no pass/fail checks
const cases: ReadonlyArray<EvalCase> = [
	{
		id: "inv-0193",
		input: "Extract vendor, total and due date: \"Birchwood Paper · Invoice 0193 · Total due €1,284.00 by 14 April\"",
		outputs: {
			small: { text: "{ vendor: \"Birchwood Paper\", total: 1284, due: \"04-14\" }", score: 0.71, latencyMs: 310 },
			medium: { text: "{ vendor: \"Birchwood Paper\", total: 1284.00, currency: \"EUR\", due: \"2026-04-14\" }", score: 0.97, latencyMs: 690 },
			large: { text: "{ vendor: \"Birchwood Paper\", total: 1284.00, currency: \"EUR\", due: \"2026-04-14\" }", score: 0.97, latencyMs: 1840 },
		},
	},
	{
		id: "inv-0207",
		input: "Extract vendor, total and due date: \"Paid in full, thank you. Harbor Print Co. $312.50\"",
		outputs: {
			small: { text: "{ vendor: \"Harbor Print Co.\", total: 312.5, due: null }", score: 0.9, latencyMs: 280 },
			medium: { text: "{ vendor: \"Harbor Print Co.\", total: 312.50, currency: \"USD\", due: null, paid: true }", score: 1, latencyMs: 640 },
			large: { text: "{ vendor: \"Harbor Print Co.\", total: 312.50, currency: \"USD\", due: null, paid: true }", score: 1, latencyMs: 1710 },
		},
	},
	{
		id: "inv-0211",
		input: "Extract vendor, total and due date: \"Due on receipt — Atelier Lumen — 3 x 420 = 1 260 CHF\"",
		outputs: {
			small: { text: "{ vendor: \"Atelier Lumen\", total: 420 }", score: 0.32, latencyMs: 300 },
			medium: { text: "{ vendor: \"Atelier Lumen\", total: 1260, currency: \"CHF\", due: \"on receipt\" }", score: 0.94, latencyMs: 720 },
			large: { text: "{ vendor: \"Atelier Lumen\", total: 1260.00, currency: \"CHF\", due: \"on receipt\" }", score: 0.96, latencyMs: 1950 },
		},
	},
]

export const ModelSizes = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.wrap)).children(
		EvalCompare(h, {
			key: "models",
			props: {
				id: "models",
				label: "Invoice extraction by model size",
				variants: [
					{ id: "small", name: "Small", detail: "fastest" },
					{ id: "medium", name: "Medium" },
					{ id: "large", name: "Large", detail: "slowest" },
				],
				cases,
			},
		}),
	)
```

## API reference

**Props**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` (required) | `string` | — | What's being compared: "Support replies: prompt v7 vs v8". |
| `variants` (required) | `EvalVariant[]` | — | Two or three, left to right. |
| `cases` (required) | `EvalCase[]` | — | — |
| `value` | `Record<string, string>` | — | Verdicts so far, by case id. |
| `filter` | `EvalFilter` | `"all"` | The filter to start on; "all" by default. |
| `id` | `string` | `"eval"` | Starts the ids inside it, unique on the page; "eval" by default. |
| `locale` | `string` | — | For the numbers; the browser's by default. |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedChange` | `{ value: Record<string, string> }` | A case was judged: every verdict so far, by case id. |

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/eval-compare
```

With npm: `npx shadcn@latest add checkfu/uicontext/eval-compare`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/eval-compare`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/eval-compare`.

It writes these files:

- `src/ui/uicontext/components/EvalCompare.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/EvalCompare.ts](https://github.com/checkfu/uicontext/blob/main/src/EvalCompare.ts)

## Related

- [Agent Tools](https://uicontext.com/docs/components/agent-tools.md) (`agent-tools`): Lets agents in the browser read the page and act through the same controls people use.
- [Tool Confirmation](https://uicontext.com/docs/components/tool-confirmation.md) (`tool-confirmation`): Asks a person to confirm before an agent's action changes anything.
- [Prompt Template](https://uicontext.com/docs/components/prompt-template.md) (`prompt-template`): Write a prompt with {{variables}} the app fills in: they stand out, unknown ones are flagged, and a preview shows it with samples.
- [Agent Settings](https://uicontext.com/docs/components/agent-settings.md) (`agent-settings`): Edit an agent's name, instructions, tools and model.
- [Computer](https://uicontext.com/docs/components/computer.md) (`computer`): The machine an agent works on: a live view of its screen, full size or as a thumbnail with Take over, and its browser with tabs and an address bar.
- [Persona Avatar](https://uicontext.com/docs/components/persona-avatar.md) (`persona-avatar`): An agent's face: a shape and a color with eyes that move with what it's doing.
