
Classify and Route Incoming Documents
Build a document-intake pipeline that classifies each incoming file (invoice, contract, resume, receipt, ID, support ticket, other) into a fixed type set, extracts a few key fields per type, and routes it to the right destination folder with a normalized filename. Locks the document-type taxonomy, per-type extraction fields, and the routing/naming rules FIRST, then builds the classify-extract-route loop, then verifies every input file was handled, classifications are in-set with an 'other' fallback, and routing is deterministic. Taxonomy-and-routing-before-build prevents files from silently vanishing or piling into a misc bucket.
Steps
Entry step: scope. Each step names the specialist role it wants; the full working prompt is expandable.
- Scope the pipelineplannerentry
doc-type taxonomy, per-type fields, routing rules
Show working prompt
Define the intake contract before building. Step 1: identify the inbox/source folder and the file types present (PDF, image, docx, email). Step 2: define the closed document-type taxonomy (e.g. invoice, contract, receipt, resume, id-document, support-ticket, other) — every file lands in exactly one, with 'other' as the explicit fallback. Step 3: for each type, list the few key fields to extract (e.g. invoice → vendor, date, total, invoice_no) and the classification signals (keywords, layout cues). Step 4: define routing and naming: destination folder per type and a normalized filename template (e.g. {type}/{date}_{vendor}_{id}.pdf), plus the dedup rule for name collisions. Step 5: write an acceptance-criteria checklist ('every input file classified into exactly one in-set type', 'an other bucket exists and is used not abused', 'per-type key fields extracted', 'each file routed and renamed deterministically', 'no file lost or overwritten', 'an intake manifest logs every file with source→destination'). Call write_task_note with taxonomy + fields + routing + checklist and write notes/scope.md. No build yet. - Build the pipelinedeveloper
classify, extract key fields, route + rename, log
Show working prompt
Implement the intake pipeline to the locked contract. Step 1: enumerate every file in the source folder. Step 2: classify each into exactly one taxonomy type using the agreed signals; when confidence is low, route to 'other' rather than guessing a specific type. Step 3: extract the per-type key fields and capture them in the manifest. Step 4: route the file to its destination folder and rename it per the template, applying the collision/dedup rule so nothing is overwritten. Step 5: append an intake-manifest row per file (source path, type, extracted fields, destination path, status) and write the manifest. Make it a runnable module and write it; confirm the manifest parses. Call write_task_note with the module path, the manifest path, and per-type counts.
- Verify the pipelinereviewer
coverage, in-set types, deterministic routing
Show working prompt
Verify the pipeline against scope. Step 1: confirm it runs and produces an intake manifest. Step 2: check coverage — the manifest has one row per source file and the count of routed files equals the count of input files (nothing lost). Step 3: confirm every classification is an in-set type and that 'other' is used for genuinely ambiguous files but not as a dumping ground for everything. Step 4: confirm routing is deterministic and collision-safe — re-running classifies the same file identically and no destination file was overwritten. Step 5: spot-check 5 files: correct type, extracted fields match the document, filename matches the template. Write PASS/FAIL per criterion to notes/verify.md and task notes; on failure, name the files and loop back to build.
- Evaluatereviewer
Grade the deliverable against every acceptance criterion. All pass → finish; any fail → loop back and fix the gap.
Show working prompt
Run intake.py (or trace it) and verify every criterion from notes/scope.md against the intake manifest. Confirm: one manifest row per source file with routed count equal to input count (no files lost or overwritten), every classification is in-set with 'other' used appropriately, per-type key fields are extracted, filenames follow the template, and routing is deterministic on re-run. Spot-check 5 files. Write PASS/FAIL per criterion; on any failure, name the files and loop back to build. Then route — this is the whole point of the loop: - **Every criterion PASSES →** call `advance_task_step({ ref, stepId: "evaluate", next: "finish" })`. - **Any criterion FAILS →** write the specific gaps to notes, then call `advance_task_step({ ref, stepId: "evaluate", next: "build" })` to loop back. The builder fixes exactly those gaps. Never route to `finish` while any criterion is unmet. The build phase's completion gate already blocked a grossly-incomplete deliverable; your job is the judgment an automated check cannot make (does it actually work, read well, look right). After ~3 unproductive loops, stop and report DONE_WITH_CONCERNS so the user can step in. - Finishdeveloper
All acceptance criteria met. Stamp a short summary and report DONE.
Show working prompt
Every acceptance criterion passed. Write a one-paragraph DONE summary to task notes via `write_task_note`: what was built, the deliverable path(s), and a one-line confirmation that each criterion is met. Then report DONE.
Triggers
Phrases that suggest this craftbook to a crew.
- sort incoming documents
- classify and file documents
- auto-route a folder of files
- document intake pipeline
- organize a dump of files
Source
View this craftbook on GitHub · MIT license