Skip to content
Talk to our solutions team

Document

bbox.Doc() returns the Doc facade — 54 methods, and the whole surface a rule has for reading a document.

Four things compose: an entry, a scope, a verb, and a coercion.

bbox.Doc() .Top(10) .Has("Closing Disclosure")
// entry scope verb
out.Set("amount", bbox.Doc().Right("Loan Amount").Currency());
// entry verb coercion

Scopes return another Doc, so they chain. Verbs end the chain, returning a Value, a boolean, a number, or a table type.

Matching is fuzzy and case-insensitive by default. You do not configure it — you opt out with Exact() or MatchCase() when a near-miss would be wrong. OCR case is unreliable, so the default is right far more often than not.

Whether the phrase appears within the current scope.

ParameterTypeMeaning
phrasestringThe phrase to look for

The edit budget is derived from the phrase, so you never supply a tolerance.

rule ClosingDisclosure "classify by the header band" salience 100 {
when
bbox.Doc().Top(10).Has("Closing Disclosure")
then
out.Set("docType", "closing_disclosure");
Retract("ClosingDisclosure");
}

Whether any of the phrases appears.

ParameterTypeMeaning
phrasesstring, variadicThe alternatives

Separate arguments replace the delimiter string the old API took: they cannot be mis-escaped, and each is matched on its own terms.

Whether every phrase appears.

ParameterTypeMeaning
phrasesstring, variadicThe phrases that must all appear
rule FormComplete "all three required sections are present" {
when
bbox.Doc().HasAll("Loan Terms", "Projected Payments", "Costs at Closing")
then
out.Set("sectionsComplete", true);
}

How many times the phrase appears in scope.

ParameterTypeMeaning
phrasestringThe phrase to count

How many pages the document has.

Each returns a narrowed Doc. They compose left to right.

Narrows to the top or bottom pct% of the page.

ParameterTypeMeaning
pctint64Page percentage

A geometric band, not a detected header. There is no fixed “header”: the production corpus uses depths of 15, 20, 25, 30, 40 and 50 percent, so the depth is yours to choose. Top(10) reads better than a rectangle and is what most rules meant.

The horizontal band between two page percentages.

ParameterTypeMeaning
fromPctint64Upper bound, as a page percentage
toPctint64Lower bound, as a page percentage

An explicit rectangle, in page percentages.

ParameterTypeMeaning
x0, y0, x1, y1int64The corners, as whole page percentages

The escape hatch for a layout the named bands do not fit. Percentages are whole numbers deliberately — a rule that needs fractional precision on a scan is a rule tuned to one document.

One page of a multi-page document, 1-indexed.

ParameterTypeMeaning
nint64The page number, from 1

The band beneath a heading, running to the bottom of the heading’s own page.

ParameterTypeMeaning
headingstringThe heading to scope beneath

Replaces the old "Heading<below>|Label" chain syntax — a chain was always a scope in disguise.

rule BorrowerSection "read the name from the borrower section only" {
when
bbox.Doc().Section("Borrower Information").Has("Name")
then
out.Set("borrowerName",
bbox.Doc().Section("Borrower Information").Right("Name").Str());
}

The band between two headings, on the start heading’s own page.

ParameterTypeMeaning
startstringThe opening heading
endstringThe closing heading

The end heading is a real boundary: when it is given but cannot be found below the start, the scope does not silently run to the page bottom.

Turns off fuzzy matching for this chain.

Makes matching case-sensitive, and exact.

Case-sensitive-but-still-fuzzy is not a combination that means anything useful, so the facade does not offer it. Reach for either when a false positive costs you something — a document code, an identifier, a legal string.

rule ExactFormCode "the form code must match exactly" {
when
bbox.Doc().Exact().Has("FORM-1099-B")
then
out.Set("formCode", "FORM-1099-B");
}

Caps a value read at px pixels from the label.

ParameterTypeMeaning
pxint64Distance in pixels

Prefer Words or Until. A pixel distance is resolution-dependent, so it does not transfer between scans of the same form.

Stops a value read after n words.

ParameterTypeMeaning
nint64Word limit

Stops a value read before the given phrase.

ParameterTypeMeaning
phrasestringWhere to stop

Anchoring to content rather than to a distance survives a change of layout, which is what makes this the best of the three limiters.

rule ReadAddressUntilNextLabel "the address runs up to the next field" {
when
bbox.Doc().Has("Property Address")
then
out.Set("propertyAddress",
bbox.Doc().Until("Loan Amount").Right("Property Address").Str());
}

Restricts a value read to the label’s own row, or to at most n rows.

ParameterTypeMeaning
nint64Row limit

The four directional verbs read a value positioned relative to a label. Each returns a Value.

Right(anchors...) → Value · Left(anchors...) → Value · Below(anchors...) → Value · Above(anchors...) → Value

Section titled “Right(anchors...) → Value · Left(anchors...) → Value · Below(anchors...) → Value · Above(anchors...) → Value”
ParameterTypeMeaning
anchorsstring, variadicOne label, or a chain

Extra labels form a chain: each anchor is located below the one before it, and the value is read in the verb’s direction from the last.

rule DateIssuedUnderClosing "the date issued that sits under the closing heading" {
when
bbox.Doc().Has("Closing Date")
then
out.Set("dateIssued",
bbox.Doc().Right("Date Issued", "Closing Date").Date());
}

That chain replaced three separate string mini-languages — a <below> form, a |> anchor path used at 111 sites, and their combinations. All three meant the same thing, and of 161 directional hops in the corpus, 146 were downward. Making them arguments rather than syntax means each label is separately checkable, so a failing chain reports which link broke rather than returning an empty string.

The value at the intersection of a row label and a column label.

ParameterTypeMeaning
rowLabelstringThe row’s label
colLabelstringThe column’s label

The honest expression for a grid. Many rules reach the same cell with a long directional chain; this says what it means.

rule PrincipalAtYearFive "the principal column, year five row" {
when
bbox.Doc().Table().Found()
then
out.Set("principalYear5",
bbox.Doc().Cell("Year 5", "Principal").Currency());
}

Whether a checkbox with the given label is ticked.

ParameterTypeMeaning
labelstringThe checkbox’s label

Scope narrows which checkbox: the detector probes the whole document, so Page(2).Checked(...) is how you reach the one on page two when the same label appears twice.

Whichever of the options is ticked, or a miss.

ParameterTypeMeaning
optionsstring, variadicThe mutually exclusive options

Scope-aware like Checked, so two copies of the same option group on different pages do not interfere.

rule OccupancyType "read the ticked occupancy option" {
when
bbox.Doc().Section("Occupancy").CheckedOption(
"Primary Residence", "Second Home", "Investment").Found()
then
out.Set("occupancy",
bbox.Doc().Section("Occupancy").CheckedOption(
"Primary Residence", "Second Home", "Investment").Str());
}

The largest line in scope — the document’s title, or a section’s heading when the scope is a section. It honours scope.

Every block of text in the current scope, in reading order.

The full OCR row containing a phrase.

ParameterTypeMeaning
phrasestringThe phrase whose row you want

This exists because a label and its value routinely share a row but land in different reading blocks — so a directional read misses, and the row does not. Reach for it when Right returns nothing and you can see the value sitting right there.

Every OCR row containing the phrase, in reading order.

ParameterTypeMeaning
phrasestringThe phrase to find rows for

The first line in scope, in reading order. Unscoped, the document’s own first line; scoped, the first row the scope contains.

How many text lines are in scope.

Typography is how you tell a heading that reads like body text from one that is actually set as a heading.

Every phrase the document renders as a heading, in reading order. A heading is a line set larger than the document’s body text.

Only the headings set at least ratio times body size.

ParameterTypeMeaning
ratiofloat64Multiple of body size

HeadingsAbove(2.0) selects headings at twice body size — the major ones.

How many headings are in scope.

IsHeading(phrase) → bool · IsTitle(phrase) → bool

Section titled “IsHeading(phrase) → bool · IsTitle(phrase) → bool”

Whether the phrase is rendered as a heading — larger or heavier than body text — rather than merely present.

ParameterTypeMeaning
phrasestringThe phrase to test

The same test under two names, so the call site can read naturally. For classification this is usually stronger evidence than presence: a form that mentions “Closing Disclosure” in a paragraph is not a Closing Disclosure.

rule ClassifyByTitle "the phrase is set as a title, not merely mentioned" salience 100 {
when
bbox.Doc().Top(20).IsTitle("Closing Disclosure")
then
out.Set("docType", "closing_disclosure");
out.Set("classificationBasis", "title");
Retract("ClassifyByTitle");
}

The point size at which a phrase is rendered, or 0 when absent.

ParameterTypeMeaning
phrasestringThe phrase to measure

Resolves the phrase the same way Has does — fuzzily, across blocks.

The document’s body text size. Informational — do not compare FontSize against it directly; use IsBigText, which handles the comparison properly.

Whether a phrase is rendered notably larger than body text.

ParameterTypeMeaning
phrasestringThe phrase to test

A pattern is a named value shape — "date", "currency", "ssn", "email", and whatever else the installed pattern pack registers.

Whether the scope contains any value of the named pattern.

ParameterTypeMeaning
patternstringThe pattern name

How many values of the pattern the scope contains.

ParameterTypeMeaning
patternstringThe pattern name

The first in-scope value of the pattern.

ParameterTypeMeaning
patternstringThe pattern name
rule UnredactedSSN "a tax identifier appears in the clear" salience 90 {
when
bbox.Doc().HasPattern("ssn")
then
findings.Critical("UnredactedSSN", "privacy",
strings.Sprintf("%d unredacted tax identifiers found",
bbox.Doc().CountOf("ssn")));
}

Patterns are how you ask “is there a thing of this kind anywhere here” without knowing its label — the privacy sweep above being the canonical case.

Full detail on the returned types is in Tables and forms.

The first table within the current scope.

Every table in scope, in document order. The scope’s bounds are page-local: each table is tested against the bounds on its own page.

How many tables are in scope.

The table containing the given text.

ParameterTypeMeaning
textstringText that appears inside the wanted table

Scope still applies, so Page(2).TableWith("Origination Charges") looks only at page two.

Starts a column-aligned extraction of the band between two headings — for sections that read like tables but are not detected as one.

ParameterTypeMeaning
startHeadingstringWhere the band starts
endHeadingstringWhere it ends. Empty means “to the bottom of the page”

Runs the named form schema within the current scope.

ParameterTypeMeaning
namestringThe registered schema name

Whether a form schema with this name is registered.

ParameterTypeMeaning
namestringThe schema name

Runs a named table or repeater schema, returning its rows.

ParameterTypeMeaning
namestringThe schema name

Returns nil, not an empty list, when no such schema is registered — so a rule can tell “no schema” from “schema found nothing”.

Whether a table or repeater schema with this name is registered.

ParameterTypeMeaning
namestringThe schema name

Returns the underlying document object.

For the cases the facade does not cover. Reaching for this is a signal that something is missing here — if you need it, that is worth reporting, because the facade is meant to be sufficient.

Turns verbose spatial logging on or off.

ParameterTypeMeaning
onboolWhether to log

It mutates the underlying document, so it affects every Doc sharing it — including reads in other rules. Turn it off again, or leave it out of anything but a debugging session.