CCAPrep
← All labs
D4·Fix the code

Batch results that silently mismatch

A nightly job classifies 20,000 documents through the Batch API. It runs without errors, but roughly a fifth of the stored classifications belong to the wrong document — and only for large batches.

batch = client.messages.batches.create(requests=requests)

while client.messages.batches.retrieve(batch.id).processing_status != "ended":
    time.sleep(30)

results = list(client.messages.batches.results(batch.id))

for doc, result in zip(documents, results):
    save_classification(doc.id, extract_label(result))

1.Why do labels attach to the wrong documents?

2.What is the correct way to match a result to its input?