Module 5: Let Claude explain the results
Goal
By the end of this module, dupcheck --summary (and the MCP tool
check_and_summarize) gives a short written summary: what happened, the likely
cause, which batches, and what to do next. Claude never sees full account
numbers or names.
The concept
Counts, not data. The engine already did the hard, exact work. Claude gets a small JSON digest: counts per rule, a per-batch breakdown and 3 masked sample groups per rule. That's a few kilobytes even for a million-line file.
Batches tell the story. A single duplicate is a mistake. Eight duplicates
that all link batch 3 to batch 4 is a pattern: the batch was sent twice. So
the engine now reports groups_by_batches:
"same_payment": {"1": 1, "2": 1, "3-4": 8}
"3-4" means a group with one line in batch 3 and one in batch 4. The config says where batch headers are, so this still works for other file formats:
batch: {header_starts_with: "5", id_start: 88, id_length: 7}
Structured output. We don't parse free text. The SDK's
client.messages.parse(..., output_format=Summary) makes Claude's reply
match a Pydantic model:
class Summary(BaseModel):
headline: str
likely_cause: str
affected_batches: list[str]
suggested_action: str
Don't trust, check. The prompt says "use only numbers from the results". The code also checks what it can: any batch the summary names that isn't in the data is removed, with a warning. Module 6 adds a full number check.
Code walkthrough
BatchSpec(config.py) is the optionalbatchsection, validated like every other field.BatchTracker(engine.py) stores only the line number of each batch header.bisectfinds the batch for any line, so memory stays small.build_summary_input(summary.py) builds the digest. It refuses an unmasked result, so a mistake can't leak data.build_requestputs everything sent to the API in one dict: model (ECHO_CHECK_MODEL, defaultclaude-opus-5-5), system prompt, the digest inside<results>tags, andoutput_format=Summary.summarizecalls the API, handles a refusal, and runscheck_summary.make_clientis a tiny function that tests replace with a fake. No test calls the real API.- The no-leak test reads every account number and name from the sample file and checks none of them appear in the request.
Try it (needs an API key):
$env:ANTHROPIC_API_KEY = "sk-ant-..."
uv run dupcheck data/sample.ach --config configs/nacha.yaml --summary --out data/results.json
Exercise
- Run the summary on
data/sample.ach. Does it find the resent batch? Check its numbers againstdata/results.json. - Remove the
batchline from a copy of the config and run it again. What does the summary say about the cause now? - In
test_summary.py, make the fake client returnaffected_batches: ["99"]. What happens?
What can go wrong
- Leaking data through samples. Samples come from the masked result only.
The
_linekey is masked too. If you add a new sensitive field, mark itsensitive: trueor it will be sent. - Invented numbers. LLMs like round, confident numbers. The prompt forbids them, and Module 6 checks every number against the stats.
- Refusals. Claude can decline a request (
stop_reason: "refusal"). The code raises a clearSummaryErrorand the check results still print. In production you can add the API's server-sidefallbacksoption, which retries the request on another model. - Cost and keys. Each summary is one API call. Keep the key in an environment variable, never in the config or the repo.