- Add scrape-fill-chunk.mjs: reusable chunk-based Payee Central scraper with resume support and concurrent instance capability - Add prompts/po-email-parser.md: LLM prompt for Coupa PO email parsing with site code extraction patterns, skip list, and trade classification - Add README.md with architecture docs, DynamoDB schema, and script index - Track output/site-state-extra-mapping.json (392 facility codes) - Remove scrape-payee.mjs and scrape-payee-notfound.mjs (superseded by chunk scraper)
181 lines
6.8 KiB
Markdown
181 lines
6.8 KiB
Markdown
You are an email parser for a purchase order ingest pipeline.
|
||
The emails are Coupa procurement platform notifications containing purchase order
|
||
data from Amazon.
|
||
|
||
Analyze the following email and extract structured data. Return ONLY valid JSON with these fields:
|
||
|
||
```json
|
||
{
|
||
"email_type": "new_po" | "revision" | "cancellation",
|
||
"po_number": "string or null",
|
||
"po_status": "string or null",
|
||
"source_system": "coupa",
|
||
"submitted_by": "string or null",
|
||
"on_behalf_of": "string or null",
|
||
"order_date": "string or null",
|
||
"revision_date": "string or null",
|
||
"last_opened": "string or null",
|
||
"acknowledged_at": "string or null",
|
||
"payment_terms": "string or null",
|
||
"requisition_number": "string or null",
|
||
"department": "string or null",
|
||
"view_order_url": "URL string or null",
|
||
"supplier": {
|
||
"name": "string or null"
|
||
},
|
||
"site_code": "string or null",
|
||
"ship_to": {
|
||
"name": "string or null",
|
||
"address": "string or null",
|
||
"street": "string or null",
|
||
"city": "string or null",
|
||
"state": "string or null",
|
||
"zip": "string or null",
|
||
"location_code": "string or null",
|
||
"attn": "string or null"
|
||
},
|
||
"total_amount": 0.0,
|
||
"currency": "USD",
|
||
"fiscal_year": "string or null",
|
||
"trade": "string or null",
|
||
"coupa_category": "string or null",
|
||
"line_items": [
|
||
{
|
||
"description": "string",
|
||
"amount": 0.0,
|
||
"currency": "USD",
|
||
"need_by": "date string or null",
|
||
"category": "string or null",
|
||
"account_code": "string or null",
|
||
"period": "string or null",
|
||
"quantity": "string or null",
|
||
"unit": "string or null",
|
||
"price": "string or null"
|
||
}
|
||
]
|
||
}
|
||
```
|
||
|
||
## email_type detection
|
||
|
||
- "new_po": email announces a new purchase order being issued
|
||
- "revision": email announces a revised/updated purchase order (look for "revised" in subject or body)
|
||
- "cancellation": email announces a PO has been cancelled
|
||
|
||
## PO number
|
||
|
||
Extract from the email subject or body. Format is a prefix + hyphen + digits:
|
||
- "2D-18206023", "FK-21088051", "B187-17955555"
|
||
|
||
## site_code extraction
|
||
|
||
The site code is the Amazon facility code — a 3-5 character alphanumeric code identifying
|
||
the delivery site. Check these locations in order:
|
||
|
||
1. Ship-to name in parentheses: "Amazon.com Services LLC (KLAL)" → KLAL
|
||
2. Ship-to name after dash: "Amazon.com Services LLC - SNY5" → SNY5
|
||
3. Ship-to ATTN line with dash or en-dash: "ATTN: Wagon Wheel DS Station –WKY3" → WKY3
|
||
4. Ship-to ATTN line directly: "Attn: HJX1" → HJX1
|
||
5. Ship-to name IS the code: if the name is just "DBU2" or similar, use it
|
||
6. Line item description prefix: "DYO1 - Sea Haven Ind - Plumbing Repairs" → DYO1
|
||
7. Line item description in brackets: "[HMK4] Assemble 3 Wire Security Cages" → HMK4
|
||
|
||
**Not site codes — do not extract these as site_code:**
|
||
- RME (Amazon Reliability Maintenance Engineering department)
|
||
- BBM (Coupa description format tag)
|
||
- JLL (Jones Lang LaSalle — facilities management vendor)
|
||
- PARAG, ERIK (vendor/person names)
|
||
- Industry acronyms: HVAC, LED, PVC, ADA, OSHA, EMR, BMS, DDC, MRO, NTE, EST
|
||
|
||
If the only candidate matches this skip list, set site_code to null.
|
||
|
||
## Ship-to address parsing
|
||
|
||
Parse the full address into separate fields. Be aware of these common issues:
|
||
- State abbreviation may be missing entirely (e.g., "Tucson, 85704" with no state)
|
||
- Zip codes may lack leading zeros (e.g., "MA 2149" should be zip "02149", "NJ 7001" should be "07001")
|
||
- City names may be misspelled (e.g., "Charoltte" for Charlotte) — extract as-is, do not correct
|
||
- Format varies: "City, ST - ZIP", "City, ST ZIP", "City, ZIP" (no state)
|
||
|
||
If state cannot be determined from the address, set ship_to.state to null.
|
||
|
||
## fiscal_year
|
||
|
||
The calendar year the work covers. Determine from:
|
||
1. The order_date year (primary source)
|
||
2. Need-by dates on line items
|
||
3. Year in line item descriptions (e.g., "HVB2 - 2025 - Plumbing PM" → "2025")
|
||
|
||
Use the 4-digit year string (e.g., "2025").
|
||
|
||
## trade classification
|
||
|
||
Classify the primary trade from line item descriptions. Use the FIRST match in priority order:
|
||
|
||
**Plumbing - PM**: "plumbing pm", "plumbing preventative", "plumbing maintenance",
|
||
or BBM format: "Plumbing - Backflow", "Plumbing - Water Heater - Install/Repair"
|
||
|
||
**Plumbing - Reactive**: "plumbing" with: "reactive", "emergency", "repair", "clog",
|
||
"unclog", "leak", "flood", "sewer", "drain", "grease trap", "jetter", "water line",
|
||
"toilet", "faucet", "urinal", "pipe"
|
||
|
||
**Electrical**: "electrical", "lighting", "ballast", "outlet", "circuit", "panel",
|
||
"generator", "transformer", "conduit" (but NOT if "dock door" context)
|
||
|
||
**HVAC**: "hvac", "heating", "cooling", "air conditioning", "RTU", "AHU", "VAV",
|
||
"refrigerant", "thermostat", "ductwork"
|
||
|
||
**Dock Doors**: "dock door", "dock leveler", "dock plate", "dock seal", "dock bumper"
|
||
|
||
**Doors**: "door", "overhead door", "roll-up", "automatic door", "access door"
|
||
(only if not matched by Dock Doors above)
|
||
|
||
**Signage**: "sign", "banner", "wayfinding", "marquee", "directional"
|
||
|
||
**Carpentry**: "carpentry", "cabinet", "millwork", "trim", "shelving", "framing"
|
||
|
||
**Fencing/Gates**: "fence", "fencing", "gate", "bollard" (not "dock gate")
|
||
|
||
**Conveyance/MHE**: "conveyor", "MHE", "material handling", "sortation"
|
||
|
||
**Painting**: "paint", "painting", "primer", "coating", "touch-up"
|
||
|
||
**Flooring**: "floor", "tile", "carpet", "epoxy", "polishing"
|
||
|
||
**Janitorial**: "janitorial", "cleaning", "custodial", "pressure wash", "power wash"
|
||
|
||
**Fire/Life Safety**: "fire", "sprinkler", "extinguisher", "fire alarm", "suppression"
|
||
|
||
**Landscaping/Yard**: "landscape", "lawn", "tree", "yard", "mowing", "irrigation"
|
||
|
||
**Roofing**: "roof", "roofing", "gutter", "downspout"
|
||
|
||
**Security/Locksmith**: "lock", "key", "access control", "camera", "security", "CCTV"
|
||
|
||
**Snow Removal**: "snow", "ice", "salt", "de-ice", "plow"
|
||
|
||
**PO Uplift**: description is exactly or primarily "PO Uplift"
|
||
|
||
**General Building - Emergency**: "EMER" prefix, or "emergency" in a general building context
|
||
|
||
**General Building - Handyman**: BBM format "General Building - General Building Technician"
|
||
|
||
**General Building - Project**: BBM format "General Building - General Building Project"
|
||
|
||
**General Building**: any remaining facility maintenance work
|
||
|
||
If a PO has multiple line items with different trades, set "trade" to the primary
|
||
(non-uplift, non-materials) trade. If genuinely mixed, use the trade of the highest-value line item.
|
||
|
||
## coupa_category
|
||
|
||
The Coupa commodity/category field if present in the email (e.g., "Maintenance - Facilities",
|
||
"Plumbing Equipment & Materials"). This is Coupa's own classification, not the trade field.
|
||
|
||
## General rules
|
||
|
||
- Extract all line items with descriptions, amounts, and metadata
|
||
- "quantity", "unit" (e.g., "EACH", "HR"), and "price" (unit price) should be extracted when present
|
||
- total_amount should be the numeric total in USD
|
||
- If a field is not present in the email, set it to null
|
||
- Do NOT invent or infer data that is not explicitly in the email
|