Evaluating LLM Apps

Gen AI · Customizing Model Behavior

Theory

Evaluation means measuring how well your LLM feature works on a fixed set of test cases, so you can tell whether a prompt, model or retrieval change made things better or worse. Start with a test set of realistic inputs and expected outputs, including edge cases and past failures, often 20 to 100 cases to begin with. Then score each output.

Scoring methods depend on the task. Exact match or rules work for labels, numbers and JSON fields. For free text, use a rubric scored by people or by a second model acting as a judge ("Is the answer supported by the context? yes or no"), and spot-check the judge against human ratings. For RAG, evaluate retrieval separately: did the right chunk appear in the top-k? Track quality alongside latency and cost, rerun the suite on every change, and add real production failures to the test set over time.

Why we use it

LLM outputs vary and a change that fixes one case can break others. A repeatable test set turns 'it looks better' into a measured pass rate, which is how you ship changes with confidence.

When to use it

Build the test set before you tune prompts, and rerun it whenever you change the prompt, model, chunking or retrieval settings. Keep monitoring in production, because real user inputs drift from your tests.

How it works

  1. Collect realistic test inputs with expected outputs
  2. Run the current version of the app on every case
  3. Score each output: exact match, rules or rubric judge
  4. Compute pass rate, plus latency and cost
  5. Is the new version better? Yes: Ship it; save scores as the baseline. No: Keep the old one; study failures.
  6. Add new production failures to the test set

Example

test_cases = [
    {"q": "Which city hosts the Jaipur office?", "expected": "Jaipur"},
    {"q": "Is the refund window 30 days?",      "expected": "Yes"},
    # ... 50 more realistic cases
]

passed = 0
for case in test_cases:
    answer = my_llm_app(case["q"])          # your app, pseudo-call
    if answer.strip() == case["expected"]:
        passed += 1

print(f"pass rate: {passed / len(test_cases):.0%}")
# Compare this number before and after every prompt or model change.

Key points

Gen AI topics

Foundations of Generative AI

Prompt Engineering

Retrieval & Embeddings

Customizing Model Behavior

AI Agents & Tool Use

Multimodal & Applied AI

Ethics, Cost & Careers

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Generative AI for the Data Stack

LLMs, prompt engineering, RAG, embeddings, agents and the tools shaping modern AI products — explained practically. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Section {{ sec.num }}

{{ sec.label }}

Gen AI  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

💡

{{ current.tldr }}

Explained

{{ para }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
See It In Action
{{ current.example }}
Key Takeaways — click to check off
{{ pt.mark }} {{ pt.text }}

Share this topic