Test Datasets and Data Mapping
This lesson explains what an evaluation dataset contains, how to make it comprehensive, how test data is generated, and how data mapping connects columns to evaluator inputs.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the fields evaluators need.
- Identify cases a comprehensive dataset includes.
- Explain the role and risks of synthetic test data.
- Distinguish SDK column mapping from cloud data mapping.
What a dataset contains
An evaluation dataset is a JSONL or CSV file with one row per test case. The columns depend on the evaluators: most need a query and a response; groundedness needs the context the answer should rely on; NLP and similarity evaluators need a ground_truth answer; agent evaluators need the conversation and tool calls or tool definitions.
{"query": "Is water damage from a burst pipe covered?", "context": "[doc-12] Sudden and accidental escape of water from pipes is covered...", "ground_truth": "Yes, sudden escape of water from a burst pipe is covered, minus the excess."}
{"query": "Can you recommend a lawyer?", "context": "", "ground_truth": "I can't recommend lawyers, but I can explain the claims process."}A dataset can hold pre-generated responses, so that evaluation only scores them, or only queries and ground truth, so that the evaluation calls the application as a target to generate the responses first. The second form tests the current version of the application.
Making a dataset comprehensive
A dataset of easy, typical questions makes every version look good. A useful dataset represents the real traffic mix and deliberately includes the cases where applications fail.
- Common requests in their real proportions, sampled from production logs where privacy rules allow.
- Edge cases: ambiguous questions, long inputs, unusual formatting, other languages.
- Out-of-scope and unanswerable questions, where the correct behaviour is to decline or say the answer is unknown.
- Multi-turn conversations where context from earlier turns matters.
- Adversarial inputs: jailbreak attempts and prompt injection, usually in a separate safety dataset.
- Regression cases: every production failure that was fixed, so it cannot return unnoticed.
Datasets are versioned, in Git or as Foundry datasets, because scores are only comparable on the same version. When a dataset changes, the baseline is re-evaluated on the new version before comparing new changes.
Generating test data
New applications have no production logs. Synthetic data generation fills the gap: a model generates question and answer pairs from the source documents, or simulates users with personas and tasks. The Azure AI Evaluation SDK includes simulators for this, including adversarial simulators that generate attack conversations for safety testing.
Synthetic data needs review. Generated questions are often easier and more literal than real ones, and generated answers can be wrong. A practical approach is to generate a large set, have subject matter experts review and correct a sample, and replace synthetic rows with real ones as production traffic arrives.
Data mapping
Data mapping tells each evaluator where each of its inputs comes from. Without it, an evaluator expecting context would not find a column named retrieved_passages. In the Azure AI Evaluation SDK, mappings are set per evaluator in evaluator_config: ${data.COLUMN} refers to a dataset column, and ${target.FIELD} refers to a field returned by the target application.
from azure.ai.evaluation import evaluate, GroundednessEvaluator, RelevanceEvaluator, F1ScoreEvaluator
judge = {"azure_endpoint": AOAI_ENDPOINT, "azure_deployment": "judge", "credential": credential}
result = evaluate(
data="eval/datasets/support_v4.jsonl",
target=ask_assistant, # returns {"response": ..., "context": ...}
evaluators={"groundedness": GroundednessEvaluator(judge), "relevance": RelevanceEvaluator(judge),
"f1": F1ScoreEvaluator()},
evaluator_config={
"groundedness": {"column_mapping": {"query": "${data.query}", "response": "${target.response}",
"context": "${target.context}"}},
"relevance": {"column_mapping": {"query": "${data.query}", "response": "${target.response}"}},
"f1": {"column_mapping": {"response": "${target.response}", "ground_truth": "${data.ground_truth}"}},
},
azure_ai_project=PROJECT_ENDPOINT,
)
print(result["metrics"])Foundry cloud evaluations use the same idea with a different syntax: each testing criterion has a data_mapping such as {"query": "{{item.query}}", "response": "{{item.response}}"}, where item is the dataset row, and outputs generated during the run are referenced from the sample, such as {{sample.output_text}}.
Wrong mappings fail silently
Mapping mistakes produce plausible but meaningless scores. Mapping the ground truth to context, for example, makes groundedness measure agreement with the reference answer instead of support by the retrieved passages. Check a few rows of results by hand after changing a mapping.
Groundedness that looks too good
A RAG assistant's groundedness score jumped from 3.9 to 4.8 after a team member rewrote the evaluation script. The application itself did not change. The new script's column mapping for groundedness is "context": "${data.ground_truth}", and the dataset's ground truth answers were written by the same experts who wrote the source documents.
The groundedness evaluator is now judging whether responses agree with the reference answers, not whether they are supported by the retrieved passages, so the score no longer measures groundedness. Map context to the passages the application actually retrieved, such as ${target.context}, rerun the evaluation, and review a sample of rows to confirm the scores make sense.
Accepting the new score would hide real fabrication. Switching to a different judge model would not fix the input. Adding similarity would add a ground-truth comparison but leave groundedness wrong.
In an evaluate() call with a target, how is an evaluator's response input mapped to the target's output?
Show answer
With column mapping in evaluator_config, for example "response": "${target.response}". Columns from the dataset use ${data.column}.
Exam Tips
Remember for the exam
- Datasets are JSONL or CSV rows of query, context, ground_truth and agent fields as evaluators need.
- Include edge cases, unanswerable questions, multi-turn and regression cases; version datasets.
- Synthetic data fills gaps but needs expert review.
- SDK mapping uses ${data.column} and ${target.field}; Foundry cloud evaluation uses {{item.column}}.