Build an AI Feature Eval Dashboard with Cost Tracking

Build a hands-on eval dashboard that scores prompt quality, tracks token cost and latency, and gives you data-driven proof that your AI feature is actually getting better.

What You'll Build

A local eval dashboard that lets you define test cases, run prompts against them, score the results, and see cost and latency data — all in one place. Here's what the finished tool will do:

  • Load a set of eval test cases (input + expected output) from a JSON file
  • Run each test case through a configurable prompt template and capture the AI output
  • Score each output as pass, fail, or partial using a simple rubric checker
  • Track token usage and estimated cost per run using real model pricing
  • Display a summary dashboard with pass rate, average latency, and total cost per eval run

What You'll Need

Claude or ChatGPT

You'll use Claude to build the Python eval runner and scoring logic. Claude Code or the web interface both work great for this project.

A Text Editor + Terminal

VS Code works perfectly. You'll be writing Python files, a JSON eval set, and running scripts from your terminal. Python 3.9+ required.

Step-by-Step Guide

Follow these five steps in order. Each one builds on the last, so by the end you'll have a fully working eval dashboard you can run against any prompt you're iterating on.

1

Design Your Eval Test Set

Before you can measure improvement, you need a set of test cases that covers the realistic inputs your AI feature will see — including edge cases. You'll create a JSON file with 6-8 test cases, each with an input, expected keywords in the output, and a difficulty label. This is the foundation everything else builds on, so don't skip the edge cases.

Prompt — send this to Claude
I'm building an eval system for a customer-facing AI feature. The feature takes a user question about a software product and generates a helpful, concise answer.

Please create a JSON file called eval_set.json with 8 test cases. Each test case should have:
- "id": a short string like "tc01"
- "input": a realistic user question
- "expected_keywords": an array of 3-5 strings that a good answer should contain
- "difficulty": one of "easy", "medium", or "hard"
- "notes": a one-line description of what makes this case tricky or important

Include at least 2 edge cases: one where the user is vague or incomplete, and one where the user asks something outside the product's scope. Make the test cases diverse — different question styles, different levels of specificity.

Return only valid JSON, no explanation text outside the JSON structure.

What to look for

Claude should return a clean JSON array with 8 objects. Check that each one has all five fields, that difficulty is spread across all three levels, and that the two edge cases are genuinely tricky — not just slightly harder easy questions. If the JSON isn't valid, ask Claude to fix it and validate it.

2

Build the Eval Runner with Latency Timing

Now you'll build the Python script that loads your eval set, runs each test case through a prompt template via the OpenAI API, and captures the response along with latency in milliseconds. Getting the timing right matters — you want wall-clock time from request start to first token received, not just processing time.

Prompt — send this to Claude
Build a Python script called eval_runner.py that does the following:

1. Loads eval_set.json from the same directory
2. Defines a prompt template as a string with a {input} placeholder, like: "You are a helpful software support assistant. Answer this user question clearly and concisely: {input}"
3. For each test case, sends the filled-in prompt to the OpenAI chat completions API using gpt-4o-mini
4. Times each API call using time.perf_counter() and records latency_ms as an integer
5. Stores the full raw response text for each test case
6. Saves results to eval_results.json — an array where each item has: id, input, raw_output, latency_ms, prompt_tokens, completion_tokens, total_tokens

Use the openai Python library. Load the API key from an environment variable called OPENAI_API_KEY. Add a 1-second delay between calls to avoid rate limits. Print a progress line to the console for each test case as it runs.

Do not add scoring logic yet — just the runner and results capture.

What to look for

The script should use time.perf_counter() around the API call, correctly pull token counts from response.usage, and write valid JSON output. Run it with a real API key and check that eval_results.json appears with all 8 entries filled in. Latency values in the 400–2000ms range are normal for gpt-4o-mini.

3

Add a Keyword Scorer and Pass/Fail Logic

Raw outputs are useless without a score. You'll add a scorer that checks each response against the expected keywords from your eval set, assigns a score from 0 to 1 based on how many keywords appear, and labels each result as pass (≥0.7), partial (0.4–0.69), or fail (<0.4). This deterministic approach is fast, free, and surprisingly effective as a first-pass filter.

Prompt — send this to Claude
Add a scoring module to my eval system. Create a new Python file called scorer.py with a function called score_result(result, eval_case) that:

1. Takes a result object (with raw_output) and an eval_case object (with expected_keywords)
2. Checks how many of the expected_keywords appear in the raw_output — do a case-insensitive substring match
3. Calculates a score: number of keywords found / total keywords (a float between 0 and 1, rounded to 2 decimal places)
4. Assigns a label: "pass" if score >= 0.7, "partial" if score >= 0.4, "fail" if below 0.4
5. Returns a dict with: score (float), label (string), keywords_found (list of matched keywords), keywords_missed (list of missed keywords)

Then update eval_runner.py to:
- Import and call score_result for each test case after getting the API response
- Add score, label, keywords_found, and keywords_missed to each item in eval_results.json

Also add a simple print statement after all runs that shows: total pass, partial, fail counts, and overall pass rate as a percentage.

What to look for

The scorer should handle case-insensitivity correctly — "integration" should match "Integration" or "INTEGRATION". Check that eval_results.json now includes score and label on every entry. The console summary at the end should show counts that add up to 8. If your pass rate is below 50%, that's a signal your prompt template needs tuning — which is exactly what this tool is for.

4

Build the Cost Calculator

Token counts alone don't tell you much until you translate them into dollars. You'll add a cost calculator that uses real per-token pricing for gpt-4o-mini and computes the cost of each individual run as well as the total for the whole eval suite. This is where the cost-awareness skills from the tutorials really click — you'll see exactly how cheap (or expensive) iterating on your prompt actually is.

Prompt — send this to Claude
Create a Python file called cost_calculator.py for my eval system. It should:

1. Define a PRICING dict at the top with per-million-token rates for gpt-4o-mini:
   - input_per_million: 0.15
   - output_per_million: 0.60

2. Have a function called calculate_cost(prompt_tokens, completion_tokens) that returns a dict with:
   - input_cost: float (rounded to 6 decimal places)
   - output_cost: float (rounded to 6 decimal places)
   - total_cost: float (rounded to 6 decimal places)
   - model: "gpt-4o-mini"

3. Have a function called summarize_costs(results_list) that takes the full eval_results list and returns:
   - total_prompt_tokens: int
   - total_completion_tokens: int
   - total_tokens: int
   - total_cost_usd: float (rounded to 6 decimal places)
   - cost_per_test_case_avg: float (rounded to 6 decimal places)
   - projected_1000_runs_usd: float (rounded to 4 decimal places)

Then update eval_runner.py to call calculate_cost for each result and add cost_breakdown to each item in eval_results.json. Call summarize_costs at the end and print a formatted cost summary to the console. Also add the cost summary to a top-level "summary" key in eval_results.json alongside the results array.

What to look for

The projected_1000_runs cost is the most useful number here — it tells you what it would cost to run your full eval suite 1,000 times as you iterate. For gpt-4o-mini with short prompts, you should see costs well under $0.01 per full eval run. If numbers look off, double-check that the per-million conversion math is right: tokens / 1,000,000 × rate.

5

Build the HTML Dashboard to Visualize Everything

The final piece is a readable dashboard that turns your eval_results.json into an HTML report you can open in any browser. It should show the summary stats at the top — pass rate, average latency, total cost — and then a row-by-row table of every test case with color-coded pass/fail labels. This is what you share with teammates or yourself when you need to prove a prompt change made things better.

Prompt — send this to Claude
Create a Python script called generate_dashboard.py that reads eval_results.json and generates a self-contained HTML file called eval_dashboard.html. The dashboard should:

1. Show a header with the title "Eval Dashboard" and a timestamp of when the report was generated

2. Display a summary row of stat cards at the top showing:
   - Overall pass rate (% of "pass" labels)
   - Total test cases run
   - Average latency in ms
   - Total cost in USD with 4 decimal places
   - Projected cost per 1000 runs in USD

3. Show a results table with one row per test case. Columns: ID, Input (truncated to 80 chars), Score, Label, Latency (ms), Cost ($), Keywords Found, Keywords Missed

4. Color-code the Label column: green background for pass, amber for partial, red for fail

5. Use a clean dark-themed design with a dark background (#0f172a), white text, and a simple table with alternating row shades

6. Make it completely self-contained — no external CSS or JS dependencies, just inline styles

The script should print "Dashboard saved to eval_dashboard.html" when done. Everything should be generated from the data in eval_results.json with no hardcoded values.

What to look for

Open eval_dashboard.html in your browser. The summary cards should match the numbers printed in your terminal. The table should have all 8 rows with correctly colored labels. Try editing your prompt template in eval_runner.py — something small like adding "Be concise and specific." to the system message — then re-run the eval and regenerate the dashboard. You should see the numbers change. That's the whole point: now you have proof.

Common Issues

The eval runner throws an AuthenticationError

Your OPENAI_API_KEY environment variable isn't set, or it's set incorrectly. In your terminal, run export OPENAI_API_KEY=sk-your-key-here before running the script. On Windows use set OPENAI_API_KEY=sk-your-key-here. The key needs to be active and have credits.

All results come back as "fail" even though the answers look fine

Your expected_keywords in eval_set.json are probably too specific, too long, or phrased in a way the model doesn't naturally use. Go back to eval_set.json and make the keywords shorter and more generic — single words or short phrases work better than full sentences. The scorer does substring matching, so "integrat" would even match "integrating" and "integration".

Cost numbers look way too high or way too low

Double-check the per-million-token math in cost_calculator.py. A common bug is dividing by 1,000 instead of 1,000,000. For gpt-4o-mini, a typical short prompt + response should cost around $0.000050 to $0.000150 per call. If you're seeing cents per call, you've got a division error.

The HTML dashboard shows "undefined" or empty cells

The dashboard generator is probably looking for a key that doesn't exist in eval_results.json. Re-run eval_runner.py first to make sure your results file is fully up to date with all fields including cost_breakdown and scoring data, then regenerate the dashboard. If you changed the JSON structure at any step, the old file won't have the new fields.

What You Learned

Eval Set Design

You built a real eval set with diverse difficulty levels and edge cases — the kind of coverage that actually catches regressions when you change a prompt.

Deterministic Scoring

You implemented keyword-based scoring with pass/partial/fail thresholds — a fast, free, reproducible way to evaluate AI outputs without calling another model.

Cost Awareness in Practice

You translated token counts into real dollar figures and projected costs at scale — the habit that separates AI features that ship from AI features that get killed by an unexpected bill.

Data-Driven Iteration

You built a workflow where every prompt change produces measurable before/after numbers. That's the foundation of serious AI feature development — no more guessing if things got better.

Tips for Going Further

🔁

Add a prompt version history

Save each eval run to a timestamped file like eval_results_v1.json, eval_results_v2.json. Then build a comparison view in your dashboard that shows pass rate and cost side by side across versions — so you can see your prompt improving over time.

🤖

Add an LLM-as-judge scorer

Keyword matching is fast, but it misses quality. Add a second scoring pass where you send each (input, output) pair to gpt-4o-mini and ask it to rate the response from 1-5 on helpfulness. Run this only on "partial" results to keep costs down.

⚡

Test multiple models in one run

Extend the runner to test gpt-4o-mini, gpt-4o, and gpt-3.5-turbo in the same eval run, then show a model comparison table in the dashboard. The cost difference between models will be eye-opening when you see pass rates next to price.

📊

Break down scores by difficulty

Add a difficulty breakdown to the summary: pass rate for easy, medium, and hard cases separately. It's common for a prompt to ace the easy cases but fail on edge cases — and that breakdown tells you exactly where to focus your next iteration.

More projects

One of 45 hands-on projects.

All projects AI Coding Tools tutorials