Product case study · November 19, 2026
Ask Claude Code to catch items lost by Python zip()
Reproduce silent data loss in Python zip(), ask Claude Code for a bounded repair, and test unequal lists and generators before accepting a batch.

Make unequal input lengths an explicit error, and finish validation before starting work on the paired records.
Your script receives three document names and two review decisions. It returns two neat pairs without an error. The third document disappears from the batch, and nothing in the output tells you it was ever there.
This is a useful debugging task for Claude Code because “keep all the records” is not a complete requirement. Should the program invent a missing decision, accept a partial batch, or stop? In this lab, you choose the rule first: unequal inputs must fail before the caller receives a batch.
Bring Bash on macOS, Linux or WSL, Python 3.10 or newer, and an installed, signed-in Claude Code. The Python fixture and reference repair were tested locally; the agent prompt is an authored exercise, not a recorded Claude run. Official sources were checked November 19, 2026. No real documents or external services are needed.
Make the missing item visible
Create a disposable folder and a small pairing function:
pair_lab=$(mktemp -d /tmp/claude-pairing.XXXXXX)
cd "$pair_lab"
cat > pairing.py <<'PY'
def pair_reviews(documents, decisions):
return list(zip(documents, decisions))
if __name__ == "__main__":
print(pair_reviews(["brief", "guide", "report"], ["keep", "revise"]))
PY
python3 --version
python3 pairing.py
The broken version prints:
[('brief', 'keep'), ('guide', 'revise')]
The report item is absent. Python’s built-in function reference documents that ordinary zip() stops at the shortest input. That behavior can be intentional, but it conflicts with this batch’s completeness rule.
Do not repair this by appending a guessed decision. The missing information belongs to the caller. Your job is to make its absence observable.
Write the contract before the agent changes anything
Save this as SPEC.md:
pair_reviews(documents, decisions) accepts two finite iterables.
For equal lengths, return a list of (document, decision) tuples in input order.
Two empty inputs return an empty list.
If either input is longer, raise ValueError during the function call.
Never return a partial batch, pad missing values, sort inputs or drop duplicates.
Support one-shot generators as well as lists.
Use Python 3.10+ and the standard library only.
Only pairing.py may change. Keep SPEC.md and test_pairing.py fixed.
Do not add file writes, network calls or other per-pair actions.
The finite-input condition matters because the result must fit in memory. A streaming pipeline with millions of records would need a different design. This exercise deliberately returns a completed list so the caller cannot begin acting on a partially validated result.
The contract also preserves repeated document names. Converting the pairs into a dictionary would quietly change that rule. An agent should not redesign your output format just because it makes an example shorter.
Keep eight acceptance checks outside the patch
Save this as test_pairing.py:
import unittest
from pairing import pair_reviews
class PairingTests(unittest.TestCase):
def test_equal_lists_keep_order_and_duplicates(self):
result = pair_reviews(["b", "a", "a"], ["keep", "revise", "keep"])
self.assertIsInstance(result, list)
self.assertEqual(result, [("b", "keep"), ("a", "revise"), ("a", "keep")])
def test_both_empty(self):
self.assertEqual(pair_reviews([], []), [])
def test_more_documents(self):
with self.assertRaises(ValueError):
pair_reviews(["a", "b"], ["keep"])
def test_more_decisions(self):
with self.assertRaises(ValueError):
pair_reviews(["a"], ["keep", "revise"])
def test_empty_documents(self):
with self.assertRaises(ValueError):
pair_reviews([], ["keep"])
def test_empty_decisions(self):
with self.assertRaises(ValueError):
pair_reviews(["a"], [])
def test_equal_generators(self):
documents = (name for name in ["a", "b"])
decisions = (choice for choice in ["keep", "revise"])
self.assertEqual(pair_reviews(documents, decisions),
[("a", "keep"), ("b", "revise")])
def test_unequal_generators_raise_during_call(self):
documents = (name for name in ["a", "b"])
decisions = (choice for choice in ["keep"])
with self.assertRaises(ValueError):
pair_reviews(documents, decisions)
Run the baseline:
python3 -m unittest -v test_pairing
Locally, eight tests ran and five failed. The equal-list, empty-pair and equal-generator cases passed; each mismatch case failed because no ValueError was raised. Python’s unittest documentation covers this named-module invocation and assertRaises check.
Notice that the last test calls the function inside the exception check. It does not iterate over the returned object. That is intentional: an agent that returns a lazy iterator has not met the contract, even if that iterator would eventually raise an error.
Give Claude the failure and a narrow editing boundary
Start claude in the practice folder and paste:
Read SPEC.md, pairing.py and test_pairing.py.
Run python3 -m unittest -v test_pairing and report the observed baseline.
Explain which record disappears from the demo and why.
Change only pairing.py to satisfy the contract, including generators.
Do not edit tests or the specification, install packages, commit or delegate.
Run the same tests after the edit and report the actual result.
Explain when a length mismatch becomes visible to the caller.
Do not claim the function verifies that documents and decisions are semantically matched.
Anthropic’s common workflows describes debugging with a reproduction and checking a repair. Review the proposed commands and the active permission settings. The editing boundary in this prompt expresses your scope; it does not create a filesystem sandbox.
If the patch uses len(documents), ask how it handles the generator case. If it catches ValueError and returns whatever pairs were collected, point to the requirement to reject the batch. Neither change meets these acceptance checks.
Inspect the repair, then test it yourself
The reference repair changes the function to:
def pair_reviews(documents, decisions):
return list(zip(documents, decisions, strict=True))
Keep the demo beneath it. PEP 618 introduced the optional length check for Python 3.10 and describes the silent-loss problem it addresses. The reference repair passed all eight tests locally.
Exit Claude and independently run:
python3 -m unittest -v test_pairing
python3 pairing.py
The tests should pass. The demo should now terminate with ValueError, because its deliberately unequal inputs remain unchanged. A traceback here is the intended rejection, not a failed repair. Exact error wording is not part of the contract.
If Python rejects the strict keyword, check the interpreter version in the same terminal. If tests cannot import pairing, check the working directory and filenames. If the test count differs, compare your test file with the published eight methods before trusting a green result.
Check why strict iteration is not a transaction
There is one trap worth seeing separately. Run this small demonstration:
python3 - <<'PY'
seen = []
try:
for pair in zip(["brief", "guide", "report"], ["keep", "revise"], strict=True):
seen.append(pair)
except ValueError:
print("mismatch detected")
print(seen)
PY
Locally, it printed mismatch detected followed by the same two pairs as the broken demo. The loop had already appended them before reaching the mismatch.
This is why the repaired function finishes building its list before returning. Keep file writes, sends and other business actions outside that construction. For this small batch, a successful return is the point at which a caller can start using the pairs. Strict iteration by itself does not roll back work already performed.
There are limits to the guarantee. Input generators are consumed, and any effects inside those generators are not undone. The test inputs are pure, finite values. Equal lengths also do not prove correct correspondence: two independently reordered lists can have the same size while pairing the wrong records. If your real data has stable IDs, matching by ID and checking missing or duplicate IDs is a separate requirement.
Your evidence at the end is specific: the function preserves ordered pairs for equal finite inputs and rejects unequal ones before returning a list. Keep that claim narrower than “the import is safe” when you bring the pattern into a larger agent-assisted project.
Sources
Checked November 19, 2026:
- Python: zip — default truncation, lazy evaluation and strict length checking.
- Python: PEP 618 — motivation and Python 3.10 introduction of the strict option.
- Python: unittest — local test execution and exception assertions.
- Anthropic: Common workflows — reproduction-driven debugging with Claude Code.
Put this to work
How to express a data-completeness requirement as an agent task with measurable acceptance checks.
Try
Repair a tiny Python pairing function in a disposable folder.
Prove it worked
Run eight tests before and after the patch, then inspect when a lazy iterator raises its error.
Keep in view
- Reproduce a pairing function that silently loses its last record.
- Give Claude Code fixed tests for equal, unequal and one-shot inputs.
- Check the difference between detecting a mismatch and preventing partial work.