About
Eval run results with pass rate, score, cost and time against a baseline, and a sortable table of graded cases.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Eval Results to your project and fits it to your theme.
Code
How Eval Results is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
"use client"
import * as React from "react"
import { EvalBaseline, EvalCase, EvalResults, EvalSort } from "@/components/ui/eval-results"
/** A docs assistant for a Postgres hosting platform, graded for correctness by an LLM judge. */
const docsQaCases: EvalCase[] = [
{
id: "c01",
input: "How do I raise the connection limit on a pooled endpoint?",
expected:
"Pooled endpoints use PgBouncer in transaction mode. Raise default_pool_size in the endpoint's pooler settings; max_connections on the compute stays the same.",
output:
"Open the endpoint's pooler settings and raise default_pool_size. The pooler runs PgBouncer in transaction mode, so max_connections on the compute does not need to change.",
score: 0.94,
status: "passed",
latencyMs: 1840,
cost: 0.0041,
grader: "llm-judge/correctness",
reasoning:
"Names the right setting and explains why compute max_connections is unaffected. Matches the reference on every claim.",
},
{
id: "c02",
input: "Can I restore a branch to a point in time from 9 days ago on the Launch plan?",
expected:
"No. The Launch plan keeps 7 days of history. Point-in-time restore beyond 7 days needs the Scale plan, which keeps 30 days.",
output: "Yes, open the branch, choose Restore and pick any timestamp in the last 30 days.",
score: 0.12,
status: "failed",
latencyMs: 1320,
cost: 0.0029,
grader: "llm-judge/correctness",
reasoning:
"States a 30 day window for the Launch plan, which keeps 7 days. The answer would send the user into a restore that fails. The retrieved chunk for plan limits ranked 6th and was cut by the 0.72 threshold.",
},
{
id: "c03",
input: "What does the error 'remaining connection slots are reserved' mean?",
expected:
"The compute hit max_connections minus superuser_reserved_connections. Use the pooled connection string or close idle sessions.",
output:
"Your compute ran out of non-reserved connection slots. Switch the app to the pooled connection string (the host ends in -pooler) or close idle sessions.",
score: 0.91,
status: "passed",
latencyMs: 2110,
cost: 0.0044,
grader: "llm-judge/correctness",
reasoning: "Correct cause and both fixes. Adds the -pooler host hint, which is accurate.",
},
{
id: "c04",
input: "Does autoscaling ever scale a compute to zero while a long query is running?",
expected:
"No. Scale to zero only happens after 5 minutes with no active connections. A running query holds a connection.",
output:
"No. Scale to zero waits for 5 minutes without any active connection, and a running query keeps its connection open.",
score: 0.97,
status: "passed",
latencyMs: 1460,
cost: 0.0031,
grader: "llm-judge/correctness",
reasoning: "Exact match on the condition and the 5 minute window.",
},
{
id: "c05",
input: "How do I enable pgvector and create an HNSW index on a 1536 dimension column?",
expected:
"CREATE EXTENSION vector; then CREATE INDEX ON items USING hnsw (embedding vector_cosine_ops);",
output:
"Run CREATE EXTENSION vector; and then CREATE INDEX ON items USING hnsw (embedding vector_cosine_ops); For 1536 dimensions the default m = 16 and ef_construction = 64 are a good start.",
score: 0.88,
status: "passed",
latencyMs: 2380,
cost: 0.0052,
grader: "llm-judge/correctness",
reasoning: "Correct statements. The tuning advice is extra but accurate.",
},
{
id: "c06",
input: "Which regions support read replicas?",
expected: "All regions except sa-east-1, where read replicas are in preview.",
output: "Read replicas are available in every region.",
score: 0.46,
status: "failed",
latencyMs: 980,
cost: 0.0019,
grader: "llm-judge/correctness",
reasoning:
"Misses the sa-east-1 exception. Partially correct, so the score is above zero, but under the 0.70 pass mark.",
},
{
id: "c07",
input: "Is logical replication supported to an external Postgres 14 subscriber?",
expected:
"Yes. Enable logical replication in project settings; subscribers on Postgres 10 and later work.",
output:
"Yes. Turn on logical replication in the project settings, then create a publication. Any subscriber on Postgres 10 or later works, so 14 is fine.",
score: 0.93,
status: "passed",
latencyMs: 1720,
cost: 0.0037,
grader: "llm-judge/correctness",
reasoning: "Correct and complete.",
},
{
id: "c08",
input: "How long do deleted projects stay recoverable?",
expected: "7 days. After that the project and its branches are removed for good.",
status: "error",
latencyMs: 30000,
grader: "llm-judge/correctness",
errorText:
"Timed out after 30 s waiting for the model. Raise the case timeout or lower concurrency, then rerun this case.",
},
{
id: "c09",
input: "What is the maximum storage per branch on the Scale plan?",
expected: "500 GB per branch, with 50 GB included and the rest billed per GB-month.",
output: "Up to 500 GB per branch. 50 GB is included and extra storage is billed per GB-month.",
score: 0.96,
status: "passed",
latencyMs: 1190,
cost: 0.0024,
grader: "llm-judge/correctness",
reasoning: "Matches the reference.",
},
{
id: "c10",
input: "Do IP allow lists apply to the pooled endpoint as well as the direct one?",
expected: "Yes, the allow list applies to every endpoint in the project, pooled or direct.",
output:
"IP allow lists only apply to direct connections. Pooled connections are protected by the password instead.",
score: 0.08,
status: "failed",
latencyMs: 1540,
cost: 0.0033,
grader: "llm-judge/correctness",
reasoning:
"Contradicts the reference: the allow list covers pooled endpoints too. Telling users the pooler is unprotected is a security-relevant error.",
},
{
id: "c11",
input: "Can I run pg_dump against a branch without waking its compute?",
expected:
"No. pg_dump needs a running compute; it wakes on connect and scales back down after.",
output:
"No. pg_dump opens a normal connection, so the compute wakes up and scales back to zero 5 minutes after the dump finishes.",
score: 0.9,
status: "passed",
latencyMs: 1610,
cost: 0.0034,
grader: "llm-judge/correctness",
reasoning: "Correct, and the 5 minute idle detail is right.",
},
{
id: "c12",
input:
"We run a multi-tenant SaaS with one schema per tenant, about 2 400 schemas today and growing by roughly 60 a week. Migrations run through a single CI job that loops over every schema. Are there limits on schema count, and will branching copy all of them?",
expected:
"No hard schema limit, but catalog size slows pg_dump and migrations. Branches are copy-on-write, so every schema is in a new branch instantly with no extra storage until data changes.",
output:
"There is no fixed limit on schemas, but with thousands of them the system catalog grows large, so pg_dump, migrations and connection startup slow down. Branches are copy-on-write: a new branch contains every schema immediately and uses no extra storage until you write to it. For the CI loop, run migrations in parallel batches of 20 to 50 schemas.",
score: 0.86,
status: "passed",
latencyMs: 3940,
cost: 0.0081,
grader: "llm-judge/correctness",
reasoning:
"Covers both questions correctly. The batching advice is reasonable and not in conflict with the reference.",
},
]
/**
* The run: a docs assistant graded case by case. Most land green; one regression stays in, as it
* would in a real run, but it is not the story.
*/
const RUN: EvalCase[] = (() => {
const passed = docsQaCases.filter((c) => c.status === "passed")
const failed = docsQaCases.find((c) => c.status === "failed")
const cases = passed.slice(0, 5)
if (failed) cases.splice(3, 0, failed)
return cases
})()
const BY_CASE: EvalSort = { key: "index", direction: "asc" }
const reducedMotion = () =>
typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches
const STOP = Symbol("stop")
/**
* Runs `script` in a loop with a `wait(ms)` that stops cleanly on unmount or once `active` turns
* false. Reduced motion never starts it.
*/
function useLoop(
script: (wait: (ms: number) => Promise<void>) => Promise<void>,
active = true,
) {
const ref = React.useRef(script)
ref.current = script
React.useEffect(() => {
if (!active || reducedMotion()) return
let alive = true
const timers = new Set<number>()
const wait = (ms: number) =>
new Promise<void>((resolve, reject) => {
const id = window.setTimeout(() => {
timers.delete(id)
if (alive) resolve()
else reject(STOP)
}, ms)
timers.add(id)
})
;(async () => {
try {
while (alive) await ref.current(wait)
} catch (error) {
if (error !== STOP) throw error
}
})()
return () => {
alive = false
for (const id of timers) window.clearTimeout(id)
}
}, [active])
}
const BY_SCORE: EvalSort = { key: "score", direction: "desc" }
const CONCURRENCY = 2
const FIT_CSS = "html,body{overflow:hidden}[data-fit-small] [data-fit-hide]{display:none!important}"
/**
* 21st shows a demo in a small frame: about 674 by 421 on a component page, 358 by 224 on a
* phone and 245 by 139 on a profile card. A demo taller than its frame gets scrollbars, which
* render white on dark pages. FitFrame fills the frame exactly instead.
*
* - "scale": the content shrinks until it fits, centered. For visuals such as orbs.
* - "crop": the content stays at full size from the top and fades out at the bottom. For text
* that streams in, where a changing scale would make the page breathe.
*
* `minWidth` lays out a wide demo (a table, a two column panel) at that width and scales it down
* to the frame, instead of letting it collapse to a narrow layout. The frame centers it, so it
* shrinks evenly on both sides.
*
* Anything marked `data-fit-hide` (state buttons, the chatcn.dev line) drops out in frames
* shorter than `hideBelow`, so a profile card shows the visual alone.
*/
function FitFrame({
children,
mode = "scale",
hideBelow = 360,
minWidth,
}: {
children: React.ReactNode
mode?: "scale" | "crop"
hideBelow?: number
minWidth?: string
}) {
const content = React.useRef<HTMLDivElement>(null)
const [cropped, setCropped] = React.useState(false)
React.useLayoutEffect(() => {
const el = content.current
if (!el) return
const measure = () => {
const vw = window.innerWidth
const vh = window.innerHeight
el.toggleAttribute("data-fit-small", vh < hideBelow)
// Layout sizes ignore the transform, so measuring never feeds back.
const w = Math.max(el.offsetWidth, el.scrollWidth)
const h = Math.max(el.offsetHeight, el.scrollHeight)
const scale = mode === "scale" ? Math.min(1, vw / w, vh / h) : 1
el.style.transform = scale < 1 ? `scale(${scale})` : ""
setCropped(mode === "crop" && h > vh + 1)
}
measure()
const observer = new ResizeObserver(measure)
observer.observe(el)
// Content that changes inside a fixed width box (a headline that cycles words) never resizes
// the box itself, so changes below it measure again on the next frame.
let frame = 0
const mutations = new MutationObserver(() => {
cancelAnimationFrame(frame)
frame = requestAnimationFrame(measure)
})
mutations.observe(el, { subtree: true, childList: true, characterData: true })
window.addEventListener("resize", measure)
return () => {
observer.disconnect()
mutations.disconnect()
cancelAnimationFrame(frame)
window.removeEventListener("resize", measure)
}
}, [mode, hideBelow])
const fade = "linear-gradient(to bottom, #000 calc(100% - 40px), transparent)"
return (
<div
className="flex w-full justify-center overflow-hidden"
style={{
height: "100dvh",
alignItems: mode === "crop" ? "flex-start" : "center",
maskImage: cropped ? fade : undefined,
WebkitMaskImage: cropped ? fade : undefined,
}}
>
<style>{FIT_CSS}</style>
<div
ref={content}
className="w-full shrink-0"
style={{ transformOrigin: mode === "crop" ? "top center" : "center", minWidth }}
>
{children}
</div>
</div>
)
}
const LATENCY_SUM = RUN.reduce((ms, c) => ms + (c.latencyMs ?? 0), 0)
const docsQaBaseline: EvalBaseline = {
label: "main, run 212",
passRate: 0.6,
avgScore: 0.71,
cost: 0.0452,
durationMs: 48_200,
}
/** The line under each 21st demo that points back to the kit. */
function MoreOn({ slug, children }: { slug: string; children: React.ReactNode }) {
return (
<p data-fit-hide className="text-[0.75rem]/[1rem] text-(color:--chatcn-fg-faint) text-center text-balance">
{children}{" "}
<a
href={`https://chatcn.dev/docs/components/${slug}`}
target="_blank"
rel="noopener"
className="text-(color:--chatcn-fg-subtle) hover:text-(color:--chatcn-fg) underline underline-offset-2"
>
chatcn.dev
</a>
</p>
)
}
/**
* An eval run against the last main run: cases finish two at a time, out of order, while the pass
* rate, score, cost and time update in place against the baseline. When it lands, the cases sort
* by score. Loops.
*/
export default function EvalResultsPreview() {
// The first frame (and 21st's cover) shows the finished run; then it runs again.
const [done, setDone] = React.useState(RUN.length)
const [sort, setSort] = React.useState<EvalSort>(BY_CASE)
useLoop(async (wait) => {
await wait(1600)
setSort(BY_SCORE)
await wait(2600)
setSort(BY_CASE)
setDone(0)
await wait(700)
for (let i = 1; i <= RUN.length; i++) {
setDone(i)
await wait(620)
}
})
const cases: EvalCase[] = RUN.map((c, i) => {
if (i < done) return c
const status = i < done + CONCURRENCY ? "running" : "queued"
return { id: c.id, input: c.input, expected: c.expected, status }
})
const running = done < RUN.length
return (
<FitFrame minWidth="46rem">
<div className="flex w-full flex-col items-center justify-center gap-4 p-6">
<EvalResults
className="w-full max-w-3xl"
title="docs-qa"
meta={`atlas-pro, ${RUN.length} cases`}
cases={cases}
running={running}
total={RUN.length}
metrics={{ durationMs: running ? Math.round((done / RUN.length) * LATENCY_SUM) : LATENCY_SUM }}
baseline={docsQaBaseline}
threshold={0.7}
sort={sort}
onSortChange={setSort}
/>
<MoreOn slug="eval-results">Eval runs with live scores against a baseline, case by case. On</MoreOn>
</div>
</FitFrame>
)
}
















