RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /Prompt Engineering Fundamentals
  6. /Ch. 19
Prompt Engineering Fundamentals

19. Prompt Evaluation

Chapter 19 of 25 · 15 min
KEY INSIGHT

Prompt quality splits into capability (does it work?) and reliability (does it work consistently?). Both dimensions require different measurement approaches. ```python def evaluate_prompt(prompt, test_cases, model): """ Multi-dimensional prompt evaluation. Args: prompt: PromptTemplate instance test_cases: list of {'input': dict, 'expected': str} model: callable that takes prompt string, returns output Returns: dict with evaluation metrics """ results = [] latencies = [] for case in test_cases: input_dict = case['input'] expected = case['expected'] start = time.time() output = model(prompt.render(**input_dict)) latency_ms = (time.time() - start) * 1000 latencies.append(latency_ms) # Multi-label scoring for partial correctness correctness = calculate_edit_similarity(output, expected) results.append({ 'input': input_dict, 'output': output, 'expected': expected, 'correctness': correctness, 'latency_ms': latency_ms }) return { 'avg_correctness': np.mean([r['correctness'] for r in results]), 'p95_correctness': np.percentile([r['correctness'] for r in results], 95), 'avg_latency_ms': np.mean(latencies), 'min_correctness': min([r['correctness'] for r in results]), 'failure_cases': [r for r in results if r['correctness'] < 0.5] } def calculate_edit_similarity(output, expected): """Levenshtein distance normalized to 0-1 score.""" from difflib import SequenceMatcher return SequenceMatcher(None, output, expected).ratio() ``` **Failure mode:** Single-metric evaluation (accuracy only) misses latent instabilities. A prompt scoring 95% accuracy may fail entirely on 5% of inputs that are common in production traffic. Tracking p5 correctness (5th percentile) surfaces these failure cases. ```python # Counterintuitive case: p5 matters more than average test_results = { 'avg_correctness': 0.94, 'p5_correctness': 0.12, # Bottom 5% are catastrophic failures 'min_correctness': 0.0, 'failure_cases': 23 # Out of 100 test cases } # This prompt is not production-ready despite high average ``` Recommended evaluation dimensions: correctness (p5, p50, p95), latency (p50, p99), format compliance rate, and input-length sensitivity. Track each dimension separately and set thresholds per dimension for production readiness.

Evaluating prompts requires metrics outside accuracy. A prompt may produce correct answers occasionally while being unreliable, slow, or brittle under input variation. Production evaluation tracks multiple dimensions.

EXERCISE

Build an evaluation harness for your most-used prompt. Create 50 test cases covering edge cases, run evaluation, and document which cases fail and why. Report p5 and p95 correctness alongside average.

← Chapter 18
Template Libraries
Chapter 20 →
A/B Testing Prompts