Route parse results to review
Use this procedure when a US streetstreetThe named linear feature along which house numbers are ordered. Decomposes into a name plus street affixes; one of the Tier 2 fine labels.-address intake needs a consistent rule for sending parser output to a review queue. Define what your downstream workflow requires first. This example requires a structured_address kind, an empty faults array, and nodes tagged house_number, street, locality, region, and postcode. A row meeting those conditions moves to a separate validation step. Whether the address exists or receives mail needs postal or geographic evidence beyond this rule.
Prerequisites
^24.22.3 || >=26.13.1"type": "module" in its package.jsonStart by installing the required packages:
- npm
- Yarn
- pnpm
- Bun
npm install mailwoman
yarn add mailwoman
pnpm add mailwoman
bun add mailwoman
The seven labelscomponent tagOne of the 25 labels in Mailwoman's address schema — street, locality, region, postcode, house_number, unit, po_box, country, venue, intersection, and others. Each parsed span carries exactly one component tag. in the script below are illustrative application decisions stated before this rule is evaluated. The first three complete streetstreetThe named linear feature along which house numbers are ordered. Decomposes into a name plus street affixes; one of the Tier 2 fine labels.-address strings are labeled ready. The 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., intersectionintersectionAn address that names a location by two crossing streets ('5th & Main') rather than a number and street. Mailwoman tags the two streets as intersection_a and intersection_b — a negative-space format that starved the early model., isolated unitunitA subdivision of a building — apartment, suite, floor — that refines a street address. Mailwoman's unit component; a designator plus identifier forms a subpremise., and row with an unsupported regionregionThe first-level administrative subdivision of a country — a US state, a French region, a province. The component between country and locality. string are labeled review. These labelscomponent tagOne of the 25 labels in Mailwoman's address schema — street, locality, region, postcode, house_number, unit, po_box, country, venue, intersection, and others. Each parsed span carries exactly one component tag. describe this intake's desired routing, as opposed to a postal authority's judgment or a verified location. The example reads no geographic database.
Apply the row rule
Save the following file as review-parses.ts:
import { createParser, decodeAsJSON, flattenTreeNodes } from "mailwoman"
type Route = "ready" | "review"
const examples: Array<[id: string, expected: Route, input: string]> = [
["A1", "ready", "1600 Pennsylvania Avenue NW, Washington, DC 20500"],
["A2", "ready", "350 5th Ave, New York, NY 10118"],
["A3", "ready", "11 W 53rd St, New York, NY 10019"],
["R1", "review", "PO Box 1234, Springfield, IL 62701"],
["R2", "review", "5th and Main"],
["R3", "review", "Suite 400"],
["R4", "review", "42 Nonexistent Ln, Zzyzx Falls, ZZ, 00000"],
]
const required = ["house_number", "street", "locality", "region", "postcode"] as const
const rows = []
let readyCorrect = 0
let reviewCorrect = 0
await using parser = await createParser()
for (const [id, expected, input] of examples) {
const result = await parser.parse(input)
const components = decodeAsJSON(result.tree)
const missing = required.filter((tag) => !components[tag])
const route: Route =
result.faults.length || result.kind.kind !== "structured_address" || missing.length ? "review" : "ready"
const [weakest] = flattenTreeNodes(result.tree).toSorted((a, b) => a.confidence - b.confidence)
if (expected === "ready" && route === "ready") {
readyCorrect++
}
if (expected === "review" && route === "review") {
reviewCorrect++
}
rows.push({
id,
expected,
route,
kind: result.kind.kind,
missing: missing.join(", "),
weakest: weakest ? `${weakest.tag} ${weakest.confidence.toFixed(3)}` : "",
})
}
console.table(rows)
const readyTotal = examples.filter((example) => example[1] === "ready").length
const reviewTotal = examples.filter((example) => example[1] === "review").length
console.log(`Labeled ready routed ready: ${readyCorrect}/${readyTotal}`)
console.log(`Labeled review routed review: ${reviewCorrect}/${reviewTotal}`)
The rule checks the kind and component tagscomponent tagOne of the 25 labels in Mailwoman's address schema — street, locality, region, postcode, house_number, unit, po_box, country, venue, intersection, and others. Each parsed span carries exactly one component tag. across the whole tree. It prints the weakest returned node score for diagnosis. The route depends on the kind, tags and faults. A stagestageOne of the dataflow stages in the runtime pipeline (normalize, locale check, kind classify, phrase group, token classify, sequence correct, reconcile, resolve). Distinct from tier (model vocabulary) and phase (plan milestone). fault sends a row to review, even when the tree still contains nodes.
Inspect the decisions
Run node review-parses.ts. The script prints this complete output:
┌─────────┬──────┬──────────┬──────────┬──────────────────────┬────────────────────────────────────────────────────┬──────────────────┐
│ (index) │ id │ expected │ route │ kind │ missing │ weakest │
├─────────┼──────┼──────────┼──────────┼──────────────────────┼────────────────────────────────────────────────────┼──────────────────┤
│ 0 │ 'A1' │ 'ready' │ 'ready' │ 'structured_address' │ '' │ 'postcode 0.914' │
│ 1 │ 'A2' │ 'ready' │ 'ready' │ 'structured_address' │ '' │ 'postcode 0.915' │
│ 2 │ 'A3' │ 'ready' │ 'ready' │ 'structured_address' │ '' │ 'postcode 0.914' │
│ 3 │ 'R1' │ 'review' │ 'review' │ 'po_box' │ 'house_number, street' │ 'postcode 0.914' │
│ 4 │ 'R2' │ 'review' │ 'review' │ 'intersection' │ 'house_number, street, locality, region, postcode' │ 'venue 0.757' │
│ 5 │ 'R3' │ 'review' │ 'review' │ 'landmark' │ 'house_number, locality, region, postcode' │ 'unit 0.029' │
│ 6 │ 'R4' │ 'review' │ 'review' │ 'structured_address' │ 'region' │ 'locality 0.841' │
└─────────┴──────┴──────────┴──────────┴──────────────────────┴────────────────────────────────────────────────────┴──────────────────┘
Labeled ready routed ready: 3/3
Labeled review routed review: 4/4
The rule sent the three rows labeled ready to downstream validation and the four rows labeled review to review. This is an executed result for seven selected example strings, without a production accuracy estimate or a confidence cutoff. For 42 Nonexistent Ln, Zzyzx Falls, ZZ, 00000, the observed reason is the missing region tag. The parser reads the text and leaves the question of whether that address exists to a later check.
The 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. row's weakest node score is 0.914, the same rounded value as the first ready row. A cutoff chosen from these seven scores would mix different query kindsquery 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 score origins. The bundled calibration metadata identifies a 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.' version older than the published 10.8.0 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.', so these raw values have no established probability interpretation. The confidence and limits explanation gives the version evidence. Use a separate, representative labeled set to evaluate any score-based policy for your 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.', localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for., and application costs.
For production intake, labelcomponent tagOne of the 25 labels in Mailwoman's address schema — street, locality, region, postcode, house_number, unit, po_box, country, venue, intersection, and others. Each parsed span carries exactly one component tag. records that cover your actual input sources before evaluating this rule. Count false ready decisions and unnecessary reviews with denominators, inspect the exact failed inputs, then change the condition that caused each error. Send rows marked ready through a separate record validation policy. The result schema defines the kind, fault, tag, and score fields used here.