Skip to main content

Route PO box records for mailing review

Use this guide when a US mailing-address intake needs to separate PO boxPO boxA numbered mailbox at a post office used as a delivery address instead of a physical street location. Mailwoman tags it as the po_box component; structurally the same family as a subpremise. records from records intended for a building-coordinate workflow. The example records a complete PO boxPO boxA numbered mailbox at a post office used as a delivery address instead of a physical street location. Mailwoman tags it as the po_box component; structurally the same family as a subpremise. parseaddress parsingThe process of decomposing a free-text postal address string into structured components — house number, street name, locality, region, postcode, and country — so a geocoder can resolve them to coordinates. as a mailing-address candidate for review and requests more input when the box has no localitylocalityThe city / town / settlement component of an address: a populated place sitting between region and neighborhood in the hierarchy., regionregionThe first-level administrative subdivision of a country — a US state, a French region, a province. The component between country and locality., or postcodepostcodeThe country-specific postcode (US ZIP, French code postal, etc.). Mailwoman handles postcode parsing entirely by rule classifier — a regex problem, not an ML one.. These are application choices. Whether the box exists and accepts mail is a question for the postal service.

Prerequisites​

  • Node.js ^24.22.3 || >=26.13.1
  • ECMAScript module project with "type": "module" in its package.json
  • Install the parser:

    sh
    npm install mailwoman

    The example uses the English modelneural classifierThe machine learning model at the core of Mailwoman's parser — a transformer encoder (~30M parameters) trained from scratch to do BIO token classification over addresses. It learns the 'grammar' of address formats; the gazetteer supplies the 'atlas.' and reads no geographic database. Save the following complete script as route-po-box.ts.

    Parse and apply a mailing intake rule​

    ts
    import { createParser, decodeAsJSON, flattenTreeNodes } from "mailwoman"

    const required = ["po_box", "locality", "region", "postcode"] as const

    await using parser = await createParser()

    for (const input of ["PO Box 1234, Springfield, IL 62701", "PO Box 1234"]) {
    const result = await parser.parse(input)
    const components = decodeAsJSON(result.tree)
    const missing = required.filter((tag) => !components[tag])
    const mailingCandidate = result.kind.kind === "po_box" && !result.faults.length && !missing.length
    const route = mailingCandidate ? "mailing-address-review" : "request-more-input"

    console.log(`${input}\nkind: ${result.kind.kind}, route: ${route}, missing: ${missing.join(", ") || "none"}`)
    console.table(flattenTreeNodes(result.tree), ["tag", "value", "start", "end"])
    }

    decodeAsJSON gives one value per tag for the required-field check. flattenTreeNodes lists the returned components in source order, and console.table prints each one's tag, value, and offsets. The rule requires both the po_box query kindquery kindThe coarse category the kind classifier assigns to the whole input — postcode_only, locality_only, structured_address, intersection, po_box, landmark, or vague — used to route processing. and a po_box node. It also checks for a localitylocalityThe city / town / settlement component of an address: a populated place sitting between region and neighborhood in the hierarchy., regionregionThe first-level administrative subdivision of a country — a US state, a French region, a province. The component between country and locality., postcodepostcodeThe country-specific postcode (US ZIP, French code postal, etc.). Mailwoman handles postcode parsing entirely by rule classifier — a regex problem, not an ML one., and an empty faults array before placing a record in this application's mailing-review queue. A missing field sends the record to a request for more input. The application supplies the US mailing-intake context, separately from the parser localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for..

    Run node route-po-box.ts. The script prints this complete output:

    text
    PO Box 1234, Springfield, IL 62701
    kind: po_box, route: mailing-address-review, missing: none
    ┌─────────┬────────────┬───────────────┬───────┬─────┐
    │ (index) │ tag │ value │ start │ end │
    ├─────────┼────────────┼───────────────┼───────┼─────┤
    │ 0 │ 'po_box' │ 'PO Box 1234' │ 0 │ 11 │
    │ 1 │ 'locality' │ 'Springfield' │ 13 │ 24 │
    │ 2 │ 'region' │ 'IL' │ 26 │ 28 │
    │ 3 │ 'postcode' │ '62701' │ 29 │ 34 │
    └─────────┴────────────┴───────────────┴───────┴─────┘
    PO Box 1234
    kind: po_box, route: request-more-input, missing: locality, region, postcode
    ┌─────────┬──────────┬───────────────┬───────┬─────┐
    │ (index) │ tag │ value │ start │ end │
    ├─────────┼──────────┼───────────────┼───────┼─────┤
    │ 0 │ 'po_box' │ 'PO Box 1234' │ 0 │ 11 │
    └─────────┴──────────┴───────────────┴───────┴─────┘

    For PO Box 1234, Springfield, IL 62701, the parser returned kind po_box and a po_box component containing PO Box 1234. The first record has the four components this intake requires, so the application routes it to mailing-address review. For PO Box 1234, the parseaddress parsingThe process of decomposing a free-text postal address string into structured components — house number, street name, locality, region, postcode, and country — so a geocoder can resolve them to coordinates. has the box component and lacks the three place fields, so the application requests more input. In both cases, delivery status and the location of a building remain unknown.

    The script makes no geocode call. A coordinate returned for a citylocalityThe city / town / settlement component of an address: a populated place sitting between region and neighborhood in the hierarchy. or post office needs its own source and precisionprecisionOf the spans the model labeled as a given tag, the fraction it got right. High precision means few false positives. Paired with recall to compute F1. evidence before any location use, and a PO boxPO boxA numbered mailbox at a post office used as a delivery address instead of a physical street location. Mailwoman tags it as the po_box component; structurally the same family as a subpremise. parseaddress parsingThe process of decomposing a free-text postal address string into structured components — house number, street name, locality, region, postcode, and country — so a geocoder can resolve them to coordinates. or a coarse place coordinate isn't a building destination. When you need a coordinate, first install and verify a geographic data bundle, then inspect the returned resolution_tier, epistemic_status, and coordinate provenance in the result schema. The confidence and limits explanation explains why a parser score answers neither the coordinate question nor the deliverability question.