Module 5 · Evaluation & production

Generating reliable synthetic test sets

5 min read

Every measurement in this course relies on a set of annotated questions. Writing 45 questions by hand is feasible; writing 500 that cover a whole corpus is not. You can generate them with an LLM from the passages… and end up with a test set that flatters the system: questions copied from the text, too easy, duplicated, sometimes unanswerable. This lesson shows how to generate a reliable synthetic set, with three filters and a review.

The synthetic question trap

Ask an LLM to "write a question about this passage", and it typically produces a question that reuses the passage's words: "What is the warranty period of the Axis chair's gas lift?" for a passage that says "The gas lift is under warranty for 10 years". Such a question is trivially easy for BM25, and does not resemble what real customers ask ("my chair keeps sinking, is that covered?").

This can be measured: lexical overlap is the share of the question's terms present in the source passage. On the 40 hand-written questions of Prism's set:

Question typeAverage lexical overlap
Lexical (codes, references)0.75
Factual0.65
Multi-source0.54
Rephrased0.26
English0.00
Average0.46

A synthetic set with an average overlap of 0.8 would overestimate lexical search and poorly measure rephrasings — precisely where systems fail.

Generating with an imposed style

The output schema guides generation:

class GeneratedQuestion(BaseModel):
    question: str = Field(description="Question qu'un VRAI client poserait, avec ses propres mots, "
                                      "sans recopier le texte")
    answer: str = Field(description="Réponse courte, tirée du passage")
    style: Literal["simple", "reformulee", "familiere"] = Field(description="Registre de la question")

The field descriptions are instructions: "a question a REAL customer would ask, in their own words, without copying the text". The style field (simple, rephrased, casual) forces diversity of register and then allows results to be broken down, like the question types of the hand-written set.

Three filters

prompt = f"Passage du centre d'aide ({chunk.title}) :\n{chunk.text}\n\nRédige une question de client."
g = llm.structured("testset_generate", GeneratedQuestion, prompt)
check_prompt = f"Passage : {chunk.text}\n\nQuestion : {g.question}"
check = llm.structured("testset_check", Answerable, check_prompt)
if not check.answerable:
    rejected["non_repondable"] += 1
    continue
if lexical_overlap(g.question, chunk.text) > max_overlap:
    rejected["trop_recopiee"] += 1
    continue
  1. Answerable: a second call checks that the passage is enough to answer. Generators regularly produce questions whose answer requires information missing from the passage; they would measure a failure that is not one.
  2. Not copied: above 60% lexical overlap, the question is rejected.
  3. Not a duplicate: two near-identical questions (embedding similarity ≥ 0.92) skew averages by counting the same case twice.
for i in range(len(kept)):
    if all(float(vectors[i] @ vectors[j]) < dedup_threshold for j in unique):
        unique.append(i)

The rejection report reads as a diagnosis of the generator: many copied questions means the prompt must insist more on rephrasing; many unanswerable ones, that the passages are too short to support a question.

What generated questions do not cover

A question generated from one passage has only one source. It must be supplemented with dedicated generations for:

  • multi-source questions (give the generator two related passages);
  • out-of-scope questions (plausible questions for the domain, with no answer in the corpus — essential for measuring "I don't know");
  • other languages if your users speak them;
  • exact references (product codes, error numbers).

Human review, always

No automatic filter replaces a review. Have a sample (at least 50 questions, or 10%) reviewed by a domain expert, with three questions: is the question realistic? Is the reference answer correct? Is the source passage really the best one? An error in the reference propagates to every measurement that uses it.

The best set: real questions

The synthetic set is for getting started and covering the corpus. As soon as the system has users, real questions are the best source: they have the right distribution of topics, phrasings and typos. Lesson 5.4 shows how production traces feed the evaluation set — and overlap_profile lets you check that a synthetic set resembles your real questions:

def overlap_profile(cases: list[TestCase], passages: dict[str, str]) -> float:
    """Recouvrement lexical moyen question/passage : comparez-le à celui de vos VRAIES questions."""

Key takeaways

  • An LLM generates questions that copy the passage: too easy, not very realistic.
  • Lexical overlap measures that bias: 0.46 on average for Prism's hand-written questions, 0.26 for rephrasings.
  • Three filters: answerable, not copied, not a duplicate; the rejection report diagnoses the generator.
  • Supplement with dedicated generations: multi-source, out of scope, other languages, exact references.
  • Review a sample, and switch to real questions as soon as possible.

Practice

  1. Compute the lexical overlap of your own real questions (or of ten questions you write) with lexical_overlap.
  2. With an API key, generate a set over the 67 passages and compare its overlap_profile with 0.46.
  3. Write a generator of out-of-scope questions for the Nimbus domain and check that none has an answer in the corpus.

Resources