Evaluating AI Models
Intermediate 22 min Module 4 of 6
Module 4 of 6

Domain-Specific Evaluation

A general medical QA benchmark shows 89% accuracy. The same model fails on clinical notes from your specific hospital system. This is not a coincidence: general benchmarks are built to be broadly applicable, which makes them systematically weak in the specialized vocabulary, reasoning patterns, and error profiles of any particular domain. This module teaches you how to build an evaluation set that actually matches your use case.

By the end of this module you will be able to

Why General Benchmarks Fail in Specialized Domains

General benchmarks like MMLU sample questions from a broad curriculum. Their strength is coverage: they touch many subjects and can compare models across a wide surface. Their weakness is that they are not built to reflect the distribution of questions that arise in any specific operational context.

Three structural mismatches explain most of the gap between benchmark performance and domain performance. Vocabulary shift: the benchmark may cover medical knowledge using textbook terminology, while your use case involves clinical abbreviations, local naming conventions for medications, and shorthand that clinicians use in notes but that never appears in textbooks. Task format shift: a benchmark may test knowledge via multiple choice, while your use case requires extracting specific fields from unstructured text or generating structured JSON output. Error tolerance shift: on a general benchmark, all errors are weighted equally. In a clinical use case, confusing two similar drug names is categorically different from failing a general science question.

The result is a model that appears capable on paper and fails in context. The evaluation framework must be built to match the context, not the curriculum.

The MEDFIT-LLM Evaluation Framework

The MEDFIT-LLM framework, introduced by Rao, Jaggi, and Naidu at IEEE RMKMATE 2025, provides a structured pipeline for evaluating large language models in healthcare settings. It is designed to address the specific challenges of domain evaluation: sparse expert availability, high error costs, and the need to evaluate both factual accuracy and structured output quality.

The framework defines four evaluation stages that apply beyond healthcare to any high-stakes domain deployment.

MEDFIT-LLM Evaluation Pipeline
STAGE 1 Domain Dataset Construction Source + edge cases STAGE 2 Automated Screening Metrics + confidence STAGE 3 Expert Calibration Confidence vs accuracy STAGE 4 Structured Output Audit Schema + extraction CALIBRATION FEEDBACK: EXPAND DATASET IF ECE > 0.10

In the first stage, you construct a dataset drawn directly from the operational context: real documents, real queries, real errors encountered in a pilot. In the second stage, you run automated screening using standard metrics alongside model confidence scores. In the third stage, domain experts review flagged examples and provide the ground truth needed to calibrate confidence against accuracy. In the fourth stage, you audit structured outputs for schema compliance and extraction accuracy.

The feedback loop between Stage 3 and Stage 1 is the most important element of the framework. If calibration reveals that the model is systematically overconfident in a particular subdomain, the response is to expand the dataset in that area and repeat the evaluation, not to accept the result.

Building a Domain Evaluation Set

A domain evaluation set has four requirements that distinguish it from a general benchmark. It must come from the right source, cover the right edge cases, receive expert review, and be sized appropriately for the risk level of the deployment.

Source selection is the most consequential decision. The evaluation set should be drawn from the same data distribution as the operational context: the same document types, the same query formats, the same user population. If you are deploying a model to answer questions about internal HR policy, your evaluation set should contain questions derived from that policy, not from a general HR knowledge base. If you are evaluating a clinical note summarization model, your evaluation set should contain clinical notes from the same system, using the same templates and abbreviations.

Edge case coverage requires deliberate effort. Left to random sampling, evaluation sets underrepresent the cases where models are most likely to fail: rare entities, ambiguous phrasing, conflicting information, inputs at the boundary of the model's knowledge. Systematic edge case identification means asking: what are the hardest examples in this domain? What are the inputs that would cause the most harm if mishandled? Those cases should be deliberately included.

Expert review is non-negotiable for high-stakes domains. A domain evaluation set without expert-validated ground truth is not a reliable evaluation tool. The expert review process should be structured: provide reviewers with clear criteria, check inter-reviewer agreement using kappa, and document disagreements rather than resolving them by majority vote. Disagreements often reveal genuinely ambiguous cases that the model should be expected to handle conservatively.

How large does a domain evaluation set need to be? +
Size depends on three factors: the variance of the domain (highly uniform domains need fewer examples), the required precision of the estimate (detecting a small difference requires more examples than detecting a large one), and the risk level of the deployment. For most enterprise pilot deployments, a dataset of several hundred expert-reviewed examples per task type is a reasonable starting point for detecting meaningful performance differences. High-risk deployments where individual errors have serious consequences should use substantially larger datasets with complete expert review. The interactive calculator in this module estimates the recommended size for your specific parameters.

Calibration: Does Confidence Match Accuracy?

Calibration measures whether a model's stated confidence predicts its actual accuracy. A perfectly calibrated model that says it is 80% confident should be correct 80% of the time on those examples. Most deployed models are not well calibrated: they are typically overconfident, meaning they state high confidence on examples where they are actually less accurate than the confidence score implies.

The Expected Calibration Error (ECE) is the standard metric for calibration. To compute it, you group model outputs into bins by confidence score (0-10%, 10-20%, and so on), compute the difference between average confidence and average accuracy within each bin, and take the weighted average of those differences across bins. A lower ECE indicates better calibration.

Why does calibration matter for domain-specific deployments? Because many deployment architectures use confidence thresholds to route queries. If a model says it is 90% confident, the system may pass the output directly to the user. If confidence is below a threshold, the query goes to a human reviewer. This routing logic only works correctly if the confidence scores are meaningful. An overconfident model will route too many uncertain outputs directly to users, bypassing the review that would catch errors.

In the MEDFIT-LLM framework, a calibration error above 0.10 triggers an expansion of the evaluation dataset and a re-evaluation cycle. This threshold is conservative by design: in healthcare contexts, overconfidence in the wrong subdomain can have serious consequences.

Evaluating Structured Outputs

Many enterprise deployments ask models to produce structured outputs: JSON objects, extraction templates, classification labels, or formatted tables. These outputs require a different evaluation approach than free-text generation.

The evaluation hierarchy for structured outputs has three levels. At the first level is schema validity: does the output parse correctly and conform to the required schema? This is a binary check and should be run on every output. A model that produces invalid JSON 2% of the time is not production-ready, regardless of how accurate the content is when the JSON is valid.

At the second level is field-level accuracy: for each required field in the schema, does the model extract or generate the correct value? This requires ground-truth labels for each field, which is more expensive to produce than a single output-level label but far more informative. Field-level accuracy reveals which parts of the extraction task are reliable and which require additional review or a different approach.

At the third level is semantic correctness: does the extracted value, even if it matches the schema, capture the intended meaning? A model might extract the correct date field from a document but interpret an ambiguous date (month/day vs. day/month) incorrectly. Semantic correctness evaluation requires human review or a secondary model specifically trained to verify extracted values.

Domain Evaluation Planner Interactive
3
2
Adjust the sliders to see your recommended evaluation parameters.
Python — Domain Evaluation Dataset Builder
import json, hashlib, random
from dataclasses import dataclass, field, asdict
from typing import Optional

@dataclass
class EvalExample:
    id: str
    source_doc: str
    query: str
    reference_answer: str
    expert_reviewed: bool = False
    expert_notes: str = ""
    is_edge_case: bool = False
    difficulty: str = "standard"  # standard | hard | adversarial
    domain_tags: list = field(default_factory=list)
    confidence_threshold: Optional[float] = None

def build_eval_set(
    source_examples: list[dict],
    edge_case_ratio: float = 0.20,
    target_size: int = 300,
    seed: int = 42
) -> list[EvalExample]:
    """
    Build a domain evaluation set from source examples.

    source_examples: list of dicts with keys:
        source_doc, query, reference_answer, is_edge_case, domain_tags
    edge_case_ratio: minimum fraction of edge cases in final set
    target_size: total examples after sampling
    """
    random.seed(seed)

    standard = [e for e in source_examples if not e.get("is_edge_case")]
    edge_cases = [e for e in source_examples if e.get("is_edge_case")]

    n_edge = max(int(target_size * edge_case_ratio), len(edge_cases))
    n_standard = target_size - n_edge

    sampled_standard = random.sample(standard, min(n_standard, len(standard)))
    sampled_edge = random.sample(edge_cases, min(n_edge, len(edge_cases)))

    all_examples = sampled_standard + sampled_edge
    random.shuffle(all_examples)

    result = []
    for raw in all_examples:
        content = f"{raw['source_doc']}::{raw['query']}::{raw['reference_answer']}"
        uid = hashlib.sha256(content.encode()).hexdigest()[:12]
        result.append(EvalExample(
            id=uid,
            source_doc=raw["source_doc"],
            query=raw["query"],
            reference_answer=raw["reference_answer"],
            is_edge_case=raw.get("is_edge_case", False),
            domain_tags=raw.get("domain_tags", []),
            difficulty="hard" if raw.get("is_edge_case") else "standard",
        ))
    return result

def export_eval_set(examples: list[EvalExample], path: str):
    with open(path, "w") as f:
        json.dump([asdict(e) for e in examples], f, indent=2)
    print(f"Exported {len(examples)} examples to {path}")
    edge_count = sum(1 for e in examples if e.is_edge_case)
    print(f"  {edge_count} edge cases ({100*edge_count/len(examples):.1f}%)")

# Usage
examples = build_eval_set(source_examples=my_raw_data, target_size=300)
export_eval_set(examples, "domain_eval_set.json")
Apply This

Identify one AI tool you use or are considering deploying. Write down three edge cases specific to your domain that would not appear in a general benchmark. For each edge case, specify: what makes it hard, what the correct answer would be, and what a wrong answer would look like. This exercise surfaces the shape of your evaluation gap before you build the dataset.

Putting It Together: Evaluation Parameters by Deployment Type

Different deployment types have different requirements for dataset size, expert review coverage, calibration thresholds, and the weight given to structured output validation.

Deployment Type Min Dataset Size Expert Review ECE Threshold Output Type Focus
Internal productivity tool 100 examples Sample review (20%) < 0.20 Free text
Customer-facing assistant 300 examples Full review of edge cases < 0.15 Text + structured
Enterprise pilot (regulated) 500 examples Full expert review < 0.10 Structured primary
Clinical or legal deployment 1,000+ examples Full expert review, dual annotators < 0.05 Structured, field-level
Knowledge Check
A model scores 91% on a general medical benchmark. You run it on 150 examples from your hospital's clinical notes and observe 74% accuracy. What is the most likely primary cause of the gap?
Correct. Distribution shift is the primary explanation: the benchmark uses textbook terminology and multiple-choice format, while clinical notes use local abbreviations, templates, and free-text formats that were not well represented in training.
Not quite. The most likely cause is distribution shift: the benchmark and the operational context differ in vocabulary, task format, and error type in ways that make benchmark performance a poor predictor of deployment performance.
You compute an Expected Calibration Error (ECE) of 0.18 for a model you are evaluating for an enterprise pilot deployment in a regulated industry. What does the MEDFIT-LLM framework suggest you do?
Correct. For a regulated enterprise pilot, the MEDFIT-LLM framework sets an ECE threshold of 0.10. An ECE of 0.18 exceeds that threshold, triggering the feedback loop: expand the domain dataset in the subdomains where miscalibration is worst, then re-evaluate.
Not quite. For a regulated enterprise pilot, the calibration threshold is 0.10. An ECE of 0.18 exceeds it. The framework's response is to expand the dataset in the subdomains where miscalibration is concentrated and run another evaluation cycle.
Was this module useful?
Before You Move On
If your domain evaluation dataset shows strong accuracy but high ECE, which part of your deployment architecture is most at risk?

References

  1. Rao, Jaggi, Naidu. "MEDFIT-LLM: A Domain-Specific Evaluation Framework for Healthcare AI." IEEE RMKMATE 2025. DOI:10.1109/RMKMATE64574.2025.11042816
  2. Es, James, Lewis, Moschitti. "RAGAS: Automated Evaluation of Retrieval Augmented Generation." arXiv:2309.15217, 2023. arxiv.org/abs/2309.15217
  3. Liang et al. "Holistic Evaluation of Language Models (HELM)." arXiv:2211.09110, 2022. arxiv.org/abs/2211.09110
  4. Hendrycks et al. "Measuring Massive Multitask Language Understanding (MMLU)." arXiv:2009.03300, 2020. arxiv.org/abs/2009.03300
  5. Lin et al. "TruthfulQA: Measuring How Models Mimic Human Falsehoods." arXiv:2109.07958, 2021. arxiv.org/abs/2109.07958
  6. NIST. "Artificial Intelligence Risk Management Framework (AI RMF 1.0)." NIST AI 100-1, 2023. doi.org/10.6028/NIST.AI.100-1
← Module 3: Human Evaluation Module 5: Red-Teaming →
You Might Also Like