A Markdown table can have unique headers and still assign a result to the wrong dataset. Suppose a PDF groups two columns under Dataset A and Dataset B, both measured as accuracy. After conversion, the labels may be flattened into Dataset A / Accuracy and Dataset B / Accuracy. If the header order is swapped while the data cells stay in place, the table renders perfectly and every number survives. A retrieval system can then cite the correct page and give the wrong result.
This is a useful companion to the dataset-label check. Checking for missing or duplicate names catches one failure. Checking the relationship between each header and its cells catches another.
Make the fixture asymmetric
Use a small synthetic table with deliberately distinct values. The source layout is equivalent to:
| Model | Dataset A / Accuracy | Dataset B / Accuracy |
|---|---|---|
| Cedar | 91 | 88 |
| Birch | 73 | 96 |
Imagine a converter emits the same cells but reverses the two dataset labels. A Markdown parser will accept it. A test that compares only the set of labels and the set of numbers will accept it too: both sets are unchanged.
For a regression fixture, record the expected association for each cell, including the row identity and complete header path. Here is a minimal check using Python's standard library. The converted list stands in for rows produced by your converter; adapt the mapping step to its actual output.
expected = {
("Cedar", "Dataset A", "Accuracy"): "91",
("Cedar", "Dataset B", "Accuracy"): "88",
("Birch", "Dataset A", "Accuracy"): "73",
("Birch", "Dataset B", "Accuracy"): "96",
}
# Deliberately swapped header paths, with the original cell positions.
headers = [("Dataset B", "Accuracy"), ("Dataset A", "Accuracy")]
converted = [("Cedar", ["91", "88"]), ("Birch", ["73", "96"])]
observed = {
(model, *header): value
for model, values in converted
for header, value in zip(headers, values, strict=True)
}
for cell, value in expected.items():
if observed.get(cell) != value:
print(f"MISMATCH {cell}: expected {value}, got {observed.get(cell)}")
The example needs Python 3.10 or later for zip(..., strict=True). It reports four mismatches for this fixture. The strict zip catches rows with a different number of cells and headers; it cannot detect a wrong association on its own. The comparison against an independently prepared source expectation is what exposes the swap.
A production test should also detect unexpected extra rows or columns, duplicate row identifiers, and duplicate header paths before building a dictionary. Otherwise one duplicate can overwrite another. Store a stable row identifier from the fixture when row labels are not unique. Keep raw cell strings for audit, and normalize numbers only under an explicit rule for units, decimal separators, and missing values.
Preserve the header path
A multi-level heading is a path, not a single string. In this example, Accuracy appears twice, so indexing that word alone cannot distinguish the columns. Store the ordered path for each cell, for example ['Dataset A', 'Accuracy'], along with its row key. Flatten it for readable Markdown if needed, but retain the structured path in the intermediate representation.
Merged cells complicate the mapping. A group label may span several columns, and an empty cell under that label can mean a continuation rather than an absent dataset. Build the path from the table's actual span structure when the extractor provides it. If the structure is ambiguous, preserve the raw location and flag it for review instead of silently filling a guessed label across the row.
Coordinates can help a reviewer locate the source cell, but a bounding box is not proof that a header was assigned correctly. Keep the document version and page number with the cell and header locations. A changed PDF may shift coordinates even when its displayed values look familiar.
Test retrieval separately
After conversion passes the structural fixture, index it and ask two paired questions: what is Cedar's accuracy on Dataset A, and what is it on Dataset B? Check the retrieved evidence for both the value and the full header path. Then check the answer and its citation. This separates an extraction error from a retrieval miss or a generation error.
Also try a negative case: ask for a dataset absent from the table. A system should avoid treating the nearest available column as the requested one. The correct response depends on the rest of the document, so run that test against a controlled fixture whose complete contents are known.
Header-path tests cost more to prepare than a Markdown syntax check because someone must establish the expected mapping from the source. Keep a small set of reviewed examples across layouts, then run both kinds of check after converter changes. When a fixture fails, the specific row and header path point directly to the relationship that needs inspection.
Top comments (0)