Skip to content
Talk to our solutions team

`bbox` — documents

bbox is the document surface. Almost every rule uses exactly one function on it — bbox.Doc() — and the rest of this page is the loading and construction surface around it.

If you are writing a rule that reads a document, you want Document, not this page.

Returns the document as the curated rule-facing facade.

ParameterTypeMeaning
namestring, optionalWhich loaded document. Omit for the usual single-document case

The name is optional because it is ceremony. In the production corpus, 3,320 of 3,360 document lookups pass the same string — so the argument earns its place only when a rule genuinely works across more than one loaded document.

rule ClassifyByHeader "identify the form from its header band" salience 100 {
when
bbox.Doc().Top(10).Has("Closing Disclosure")
then
out.Set("docType", "closing_disclosure");
Retract("ClassifyByHeader");
}

Everything a rule does with a document starts here and chains: a scope, a verb, a coercion. See Document for the 54 methods on the returned Doc.

Returns a previously loaded document as the raw document object.

ParameterTypeMeaning
namestringThe document name

Most deployments hand documents to the engine before rules run, so a rule rarely loads one itself. These exist for rules that genuinely need to reach a second document — a prior version to compare against, a schedule referenced by the main form.

bbox.LoadFromFile(name, path) → Document, error

Section titled “bbox.LoadFromFile(name, path) → Document, error”

Loads an OCR document from a JSON file and analyses it.

ParameterTypeMeaning
namestringThe name to register it under
pathstringPath to the JSON file

A sibling page image with the same basename — .png, .jpg, .jpeg — is attached automatically for single-page documents, which is what enables the visual checks such as Checked.

bbox.LoadFromBytes(name, data) → Document, error

Section titled “bbox.LoadFromBytes(name, data) → Document, error”
ParameterTypeMeaning
namestringThe name to register it under
databytesThe document JSON

bbox.LoadFromReader(name, r) → Document, error

Section titled “bbox.LoadFromReader(name, r) → Document, error”
ParameterTypeMeaning
namestringThe name to register it under
rreaderA stream of document JSON

bbox.LoadFromMap(name, data) → Document, error

Section titled “bbox.LoadFromMap(name, data) → Document, error”

Loads from a map, which is the shape a caller injecting a document through the CLI produces.

ParameterTypeMeaning
namestringThe name to register it under
datamap{"pages": [{"number": 1, "width": 612, "height": 792, "words": [...]}]}

bbox.LoadFromEnv(name, envVar) → Document, error

Section titled “bbox.LoadFromEnv(name, envVar) → Document, error”

Loads from a path held in an environment variable.

ParameterTypeMeaning
namestringThe name to register it under
envVarstringThe environment variable holding the path

bbox.GetOrLoad(name, path) → Document, error

Section titled “bbox.GetOrLoad(name, path) → Document, error”

Returns the document if already loaded, otherwise loads it from path.

ParameterTypeMeaning
namestringThe document name
pathstringWhere to load from if absent

The idempotent form, and the right one in a rule that may fire more than once.

bbox.MustLoadFromFile(name, path) → Document

Section titled “bbox.MustLoadFromFile(name, path) → Document”

Loads or panics.

ParameterTypeMeaning
namestringThe name to register it under
pathstringPath to the JSON file

Intended for host initialisation, where a missing document means the run cannot proceed. In a rule, prefer GetOrLoad and branch on the result — a panic takes the whole execution down, including the findings already collected.

Whether a document with this name is loaded.

ParameterTypeMeaning
namestringThe document name
rule ComparePriorVersion "only compare when a prior version was supplied" {
when
bbox.Has("prior") && bbox.Doc("prior").Has("Loan Amount")
then
out.Set("priorAmount", bbox.Doc("prior").Right("Loan Amount").Currency());
}

Every loaded document name. Diagnostic — log it when a named lookup returns nothing.

Removes one document.

ParameterTypeMeaning
namestringThe document to remove

Removes every loaded document.

Both are host-lifecycle operations. A rule that removes the document other rules are about to read is a rule whose ordering now matters in a way nothing else expresses.

These build the coordinate and direction values the older document methods take. Rules written against bbox.Doc() need none of them — Top(10), Right("Label") and Region(...) take plain numbers and strings.

ParameterTypeMeaning
x0, y0, x1, y1float64The rectangle’s corners
ParameterTypeMeaning
x, yfloat64The coordinates
ParameterTypeMeaning
namestring"right", "left", "above" or "below"

Same vocabulary, for the methods that take a relative direction.

ParameterTypeMeaning
namestring"right", "left", "above" or "below"

bbox.GeoBox(x0, y0, x1, y1) → Box · bbox.GeoDir(name) → Direction

Section titled “bbox.GeoBox(x0, y0, x1, y1) → Box · bbox.GeoDir(name) → Direction”

The geometry-package forms, for the fuzzy-search methods.

ParameterTypeMeaning
namestring"right", "left", "up" or "down" — note up/down, not above/below

The vocabulary difference between Dir and GeoDir is a genuine trap: bbox.GeoDir("above") is not a direction this constructor knows.

bbox.ExtractColumnAlignedSection(docName, sectionStart, sectionEnd, columnHeaders) → list of map

Section titled “bbox.ExtractColumnAlignedSection(docName, sectionStart, sectionEnd, columnHeaders) → list of map”

Extracts rows from a columnar form section: auto-detects column positions from the page header labels, finds the section boundaries by fuzzy match, and returns the rows between them.

ParameterTypeMeaning
docNamestringThe document name
sectionStartstringThe heading the section starts at
sectionEndstringThe heading it ends at
columnHeadersstringPipe-delimited column labels

For anything new, prefer bbox.Doc().Rows(start, end) — it is the same capability on the curated facade, with per-column naming and typing, and it does not need the document name.

rule ExtractPaymentSchedule "pull the payment schedule rows" {
when
bbox.Doc().Has("Payment Schedule")
then
out.Set("schedule",
bbox.ExtractColumnAlignedSection("page", "Payment Schedule", "Total",
vocab.List("schedule_columns")));
}

Note vocab.List supplying the pipe-delimited headers — the two features are built to fit.

bbox.PostprocessRows(rows, key, fn) → list of map

Section titled “bbox.PostprocessRows(rows, key, fn) → list of map”

Applies a named operation to the string value at key in every row.

ParameterTypeMeaning
rowslist of mapThe rows to clean
keystringThe column to operate on
fnstringThe operation
fnEffect
trimStrip leading and trailing whitespace
upperUpper-case
lowerLower-case
normalize_spacesCollapse runs of whitespace to one space
trim_currencyRemove currency symbols and separators

Call it repeatedly to chain operations on the same column.

rule CleanScheduleAmounts "normalise the amount column before storing" {
when
out.Has("schedule")
then
out.Set("schedule",
bbox.PostprocessRows(
bbox.PostprocessRows(to.Rows(out.Get("schedule")), "amount", "trim"),
"amount", "trim_currency"));
}

The nesting is the chaining — each call returns the rows for the next to take. Beyond two or three steps, a Rows read with typed columns is clearer.