← Learning guides

Worked tutorial · about 40 minutes

Audit a retrieved answer: a citation is only the first check

Separate missing evidence, unsupported claims, incomplete answers and correct refusals using six invented library questions and a downloadable review sheet.

Original editorial exercise · fictional practice data · checked 23 October 2026

A document assistant can cite a real document and still answer the wrong question. This exercise gives you canned answers and their retrieved context, so you can inspect the failure rather than install a retrieval framework. Your deliverable is a six-case review with a reason for each failure and a reproducible count of the results.

Unlike a lookup-building exercise, this starts after retrieval and generation. There is no live model, embedding service or real library information. All notices, questions and responses below are invented.

1. Read the reference collection

D1
North branch: standard loans last 14 days. One renewal is allowed when no hold is waiting. This notice does not state fee amounts.
D2
North branch desk: open Monday to Friday, 09:00-17:00; closed Sundays. Saturday hours are not listed.
D3
South branch: standard loans last 21 days. This notice does not set North branch rules.
D4
North branch headphones are for use inside the library only. Headphone loans for home use are not available.

Keep branch names and day names attached to the facts. A South branch rule cannot establish a North branch rule. A Monday-to-Friday opening time cannot establish a Saturday time. A missing fee amount is unknown, not zero.

2. Inspect the six answers against only their retrieved context

For each case, open the context documents listed with it. Mark support and completeness separately. “Supported” means every stated factual claim follows from those documents. “Complete” means the answer addresses the question, including necessary conditions. A correct unknown response can be complete when the collection does not contain the requested fact.

E1: How long is a standard North branch loan?

Retrieved context: D1

A standard North branch loan lasts 14 days [D1].

E2: How long is a standard North branch loan?

Retrieved context: D3

A standard North branch loan lasts 21 days [D3].

E3: When does the North branch desk open on Saturday?

Retrieved context: D2

It opens at 09:00 on Saturday [D2].

E4: Can North branch headphones be taken home?

Retrieved context: D4

No. North branch headphones are for use inside the library only [D4].

E5: Under what condition can I renew a North branch loan?

Retrieved context: D1

The notice mentions one renewal [D1].

E6: What fee does the North branch charge for a late return?

Retrieved context: D1

The available notice does not state a fee amount, so I cannot determine it from this notice [D1].

Before opening the key, identify one retrieval failure, one day-of-week overreach, and one answer that states a supported fact but omits the requested condition. Also decide which unknown response is appropriate. Checking that a citation ID exists is a separate, simpler check.

3. Compare with the worked answer key

Show the six decisions and their reasons
  • E1 passes. D1 supplies the North branch's 14-day period, and the response answers the question.
  • E2 fails retrieval and answer support. D1 is the required reference, but only D3 was retrieved. D3 describes a different branch. The citation exists, yet it cannot support the North branch claim. With that context alone, a safe response would state that the North branch period cannot be determined.
  • E3 fails support and abstention. D2 explicitly leaves Saturday hours unspecified. Extending weekday hours to Saturday invents a fact.
  • E4 passes. D4 directly rules out home use of the headphones.
  • E5 is supported but incomplete. The notice does mention one renewal. The answer fails to give the condition the user requested: no hold may be waiting. This wording is not a claim that renewal is always allowed, but it still does not answer the full question.
  • E6 passes by stating the limit. D1 does not give a fee amount. The answer correctly leaves it unknown rather than claiming a free or paid amount.

4. Tally the labels without pretending to automate judgment

Save the four downloads in one folder and run the standard-library Python script:

python evaluate_retrieval.py cases.json answer_annotations.csv

The script checks IDs and tallies the supplied example annotations. It does not read the meaning of an answer. If you rewrite an answer or change a notice, review its labels again; rerunning old labels would only reproduce your old assessment.

Show the complete tally script
"""Tally supplied example annotations of invented retrieval cases; not a semantic grader.
Usage: python evaluate_retrieval.py cases.json answer_annotations.csv
Python 3, standard library only. Reads files; prints JSON; makes no service calls.
"""
import csv
import json
import sys


def evaluate(cases_path, annotations_path):
    with open(cases_path, encoding="utf-8") as stream:
        data = json.load(stream)
    documents, cases = data["documents"], data["cases"]
    ids = [case["id"] for case in cases]
    if len(set(ids)) != len(ids) or not ids:
        raise ValueError("Cases need unique IDs and at least one case")
    annotations = {}
    with open(annotations_path, encoding="utf-8-sig", newline="") as stream:
        reader = csv.DictReader(stream)
        if reader.fieldnames != ["case_id", "supported", "complete", "abstained"]:
            raise ValueError("Unexpected annotation columns")
        for row in reader:
            key = row["case_id"]
            if key in annotations or any(row[field] not in ("0", "1") for field in ("supported", "complete", "abstained")):
                raise ValueError("Expected one binary annotation per case")
            annotations[key] = {field: row[field] == "1" for field in ("supported", "complete", "abstained")}
    if set(annotations) != set(ids):
        raise ValueError("Annotations must match case IDs exactly")
    results = []
    for case in cases:
        if type(case["answerable"]) is not bool:
            raise ValueError("answerable must be a boolean")
        if any(key not in documents for key in case["context_ids"] + case["reference_ids"]):
            raise ValueError("Unknown document ID")
        annotation = annotations[case["id"]]
        # This exercise uses one required reference document per answerable question.
        hit = bool(case["reference_ids"]) and set(case["reference_ids"]).issubset(case["context_ids"])
        citation_check = bool(case["citations"]) and set(case["citations"]).issubset(case["context_ids"])
        should_abstain = not case["answerable"] or not hit
        behavior_ok = annotation["abstained"] == should_abstain
        passed = citation_check and annotation["supported"] and annotation["complete"] and behavior_ok and (not case["answerable"] or hit)
        results.append({"id":case["id"], "answerable":case["answerable"],
                        "reference_in_context":hit, "citation_ids_available":citation_check,
                        **annotation, "abstention_behavior_ok":behavior_ok, "end_to_end_pass":passed})
    answerable = [row for row in results if row["answerable"]]
    unanswerable = [row for row in results if not row["answerable"]]
    def count(rows, field):
        return {"passed":sum(row[field] for row in rows), "total":len(rows)}
    return {"cases":results, "retrieval_on_answerable":count(answerable,"reference_in_context"),
            "citation_id_check":count(results,"citation_ids_available"),
            "supported_answer_key_cases":count(results,"supported"),
            "correct_abstention_on_unanswerable":count(unanswerable,"abstained"),
            "end_to_end":count(results,"end_to_end_pass"),
            "note":"Counts tally supplied answer-key labels. Changing an answer requires fresh review."}


if __name__ == "__main__":
    if len(sys.argv) != 3:
        raise SystemExit("Usage: python evaluate_retrieval.py cases.json answer_annotations.csv")
    print(json.dumps(evaluate(sys.argv[1], sys.argv[2]), indent=2))
Answer-key counts, not a real model benchmark
CheckResultWhat it tells you
Required reference retrieved for answerable questions3/4E2 lacks D1; the two unanswerable questions are excluded.
Citation IDs present in retrieved context6/6All IDs exist; this does not establish factual support.
All claims supported, according to the supplied answer-key labels4/6E2 and E3 make unsupported claims.
Correct abstention on unanswerable questions1/2E6 acknowledges the gap; E3 invents an opening time.
End-to-end pass under this exercise's rubric3/6E1, E4 and E6 pass all applicable checks.

5. Choose the layer to fix

For E2, first make branch-specific retrieval bring back D1, then recheck the answer. For E3, constrain the answer to what its evidence establishes. For E5, make completeness checks cover important conditions. Do not expect a better retriever alone to repair an incomplete response, or a valid citation string to prevent an invented claim.

A larger evaluation needs representative questions, explicit annotation rules and review of disputed labels. Add real permitted examples of your own after this practice, while keeping a separate evaluation set when tuning the system. Six invented cases can expose mechanisms; they cannot estimate reliability for real library patrons.

To practice a different evaluation problem, use the precision and recall tutorial. To choose training that addresses the gap you found, use the course evidence worksheet.

Sources and scope

The case collection, rubric and code are our editorial exercise. Hugging Face's RAG evaluation cookbook describes evaluation datasets and evaluators. Ragas documents faithfulness as claim support from context. These binary answer-key labels are not the Ragas metric or an automated judge result. Sources checked 23 October 2026.