How do you evaluate LLM applications?
Learning path, stage 5 of 5: Shipping to production · question 1 of 10Build an eval set of real inputs with defined success criteria, score outputs automatically wherever you can, and run it on every prompt, model or code change, just like tests. Use exact or programmatic checks first, LLM-as-judge with a rubric for subjective qualities, and human review to calibrate the judge and spot-check.
Building the eval set
- Start with 20–100 real cases from logs or user research, including edge cases and adversarial inputs.
- Define success criteria that are specific and measurable: "valid JSON with the right category" beats "good output".
- Add every production failure as a new case, so it can't regress.
Grading methods, best first
- Code-based: exact match, regex, JSON schema, unit tests on generated code, SQL result equality.
- LLM-as-judge: a rubric, a score per criterion, reasoning before the score. Watch for position bias, length bias and self-preference. Swap the order and use a different model where you can.
- Human: the gold standard but slow. Use it to label calibration sets.
Online
Also track production signals: thumbs up or down, edits, retries, escalations, task completion. Offline evals and live metrics complement each other.
Sources
Code example
1// An eval runner: code checks first, LLM judge for tone, a CI pass threshold.2import Anthropic from "@anthropic-ai/sdk";3import { z } from "zod";4import { zodOutputFormat } from "@anthropic-ai/sdk/helpers/zod";56interface Case { input: string; mustMention: string[] }7const client = new Anthropic();8const Grade = z.object({ reasoning: z.string(), polite: z.boolean(), score: z.number().int().min(1).max(5) });910export async function runEvals(cases: Case[], app: (input: string) => Promise<string>) {11 let passed = 0;12 for (const c of cases) {13 const out = await app(c.input);14 const codeOk = c.mustMention.every((m) => out.toLowerCase().includes(m.toLowerCase()));1516 const judged = await client.messages.parse({17 model: "claude-opus-5-5",18 max_tokens: 1024,19 messages: [{ role: "user", content: `Grade this support reply for politeness and helpfulness (1-5).\n<reply>${out}</reply>` }],20 output_config: { format: zodOutputFormat(Grade) },21 });22 if (codeOk && judged.parsed_output && judged.parsed_output.score >= 4) passed++;23 }24 const rate = passed / cases.length;25 if (rate < 0.9) throw new Error(`Eval pass rate ${rate.toFixed(2)} below 0.90`);26 return rate;27}
To run it: follow the one-time setup guide, add npm i @anthropic-ai/sdk zod @opentelemetry/api vitest, save the code as a .ts file and run npx tsx file.ts. Anything marked declare is a part you supply.
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the AI Agents & LLMs set.