Skip to content

Expression Syntax Reference

Logic block expressions define validation rules that evaluate against extracted document data. This page covers all supported syntax.

Reference extracted field values using the $ prefix followed by the field name:

$invoice_number
$total_amount
$vendor_name

Field names must exactly match the names defined in the Processor. Use snake_case naming.

For fields inside a group, use the same $field_name syntax — the expression context determines which group instance is being evaluated.

Text values are written as plain tokens, without quotes:

$vendor_name = Acme Corp
$status != void

Multi-word text stays a single token. Quotes are only needed when the text would otherwise be read as an operator, number, or boolean — for example a literal dash is the token "-", and the literal text 100 is "100". Typing quotes in the expression editor marks the token as text and strips the quotes.

Numeric literals (integer or decimal):

$total_amount > 0
abs($expected - $actual) < 0.01
$tax_rate = 8.25

Dates are represented internally as Unix timestamps in milliseconds:

$invoice_date > 1719806400000

The value 1719806400000 represents July 1, 2024. The expression builder provides a date picker that converts selected dates to timestamps automatically, and the date() function parses readable date text:

$invoice_date >= date(2024-07-01)
Operator Description Example
+ Addition $subtotal + $tax
- Subtraction $expected - $actual
* Multiplication $unit_price * $quantity
/ Division $total / $count
^ Exponentiation $base ^ 2
Operator Description Example
= Equal to $status = approved
!= Not equal to $vendor_name != ""
> Greater than $total_amount > 0
< Less than $discount < 100
>= Greater than or equal $quantity >= 1
<= Less than or equal $tax_rate <= 10

Numeric = comparisons tolerate rounding differences smaller than a cent.

Operator Description Example
and Both conditions must be true $total > 0 and $status = approved
or At least one condition must be true $status = approved or $status = pending
not Negates the following condition not $is_void

Use parentheses to control evaluation order:

($subtotal + $tax) = $total_amount
($status = approved or $status = pending) and $total > 0

Functions are grouped the same way as the picker in the expression editor.

Function Description
sqrt(x) Square root
abs(x) Absolute value
round(x, decimals?) Round to the nearest whole number, or to the given number of decimal places
roundDown(x) Round down to the nearest whole number
roundUp(x) Round up to the nearest whole number
max(a, b, ...) Largest of two or more numbers
min(a, b, ...) Smallest of two or more numbers
mod(a, b) Remainder after dividing a by b

Text comparisons are case-sensitive.

Function Description
contains(text, search) True when text contains search
startsWith(text, prefix) True when text begins with prefix
endsWith(text, suffix) True when text ends with suffix
length(text) Number of characters
upper(text) Uppercase copy of the text
lower(text) Lowercase copy of the text
trim(text) The text without leading or trailing spaces
concat(a, b, ...) Joins two or more values into one text
matches(text, pattern) True when the text matches a regular expression; an invalid pattern is false
fuzzyEquals(a, b, threshold?) Tolerant text comparison — forgiving of typos and case. Optional threshold 0–1, lower is stricter (default 0.4)

All date math uses UTC and truncates to the calendar day.

Function Description
today() Today’s date
date(text) Parses date text (e.g. 2024-07-01 or 7/1/2024) into a comparable date
year(d) The year, e.g. 2024
month(d) The month, 1–12
day(d) The day of the month, 1–31
weekday(d) The day of the week: 1 = Monday through 7 = Sunday
addDays(d, n) The date n days after d (negative n goes backward)
daysBetween(from, to) Whole days from one date to another
Function Description
exists(field_name) True when the field was extracted with a non-empty value. Takes the bare field name, without the $ — a $field reference would substitute the value first
isEmpty(field_name) True when the field is missing or empty (bare field name, without $)
isOneOf(value, option1, option2, ...) True when the value equals any of the listed options
if(condition, true_value, false_value) Returns true_value when the condition holds, otherwise false_value
lookup(value, Constant, lookup_column, return_column) Finds value in a column of a Constant and returns the matching value from another column. Falls back to fuzzy matching when there is no exact match

These aggregate across all rows of a repeating field group within a single document. They take the bare field name, without the $.

Function Description
sumItems(field) Total of the field across all rows
avgItems(field) Average of the field across all rows
countItems(field) Number of rows
minItems(field) Smallest value across all rows
maxItems(field) Largest value across all rows
sumItemsIf(field, { condition }) Total of the field over only the rows matching the condition
countItemsIf(field, { condition }) Number of rows matching the condition

Inside the { } condition, reference the row’s fields with a double prefix — $$row_field — while single $field still refers to the document. For example, summing only labor line totals:

sumItemsIf(line_total, { $$item_type = labor }) = $labor_total

A logic block can reference fields from at most one repeating group.

These reach beyond the document being evaluated — into other documents of a processor or external data. They depend on document history: associated needs an id field and repeat uploads; lookback and lookahead need a primary date field.

Function Description
sumAll(field_name, processor) Total of a field across all documents of a processor, counting each id once (most recent upload wins)
avgAll(field_name, processor) Average of a field across all documents of a processor
lookback(field_name, processor, { condition }) Scans documents backward from this document’s primary date and returns the field value from the most recent document matching the condition; false when nothing matches
lookahead(field_name, processor, { condition }) The same, scanning forward
associated($id, field_name, processor) The field’s value from the most recent earlier upload sharing this document’s id; false when none exists
cpi(start_date, end_date) US CPI inflation ratio between two dates — multiply a base amount by it to inflation-adjust

Inside a lookback/lookahead { } condition, $$field reads the candidate document being scanned, while single $field is this document’s value. For example, the amount from the last approved document:

lookback(amount, invoices, { $$status = approved }) > 0
$total_amount > 0

Ensures the total amount is positive.

exists(vendor_name) and exists(invoice_number)

Ensures both vendor name and invoice number were extracted with values.

abs($expected - $actual) < 0.01

Checks that two values are within a penny of each other.

isOneOf($status, approved, pending)

Checks the status against a list of acceptable values.

matches($reference_code, ^REF-\d{4}$)

Checks that the reference code matches the expected pattern.

sumItems(line_item_amount) = $total_amount

Verifies that the sum of all line item amounts equals the document total.

addDays($invoice_date, 30) = $due_date

Checks that the due date is exactly 30 days after the invoice date.

weekday($delivery_date) <= 5

Ensures the delivery date falls on a weekday.

($subtotal + $tax) = $total_amount and $total_amount > 0

Validates that subtotal plus tax equals the total, and the total is positive.

lookup($procedure_code, rate_schedule, procedure, rate) >= $billed_amount

Looks up the expected rate for a procedure code from the “rate_schedule” constant and checks that the billed amount does not exceed it.

daysBetween($invoice_date, today()) <= 365

Checks that the invoice date is within the last year.

if($is_taxable, $subtotal * 1.1, $subtotal) = $total_amount

Applies a 10% tax if the item is taxable, then checks the result matches the total.

associated($id, rate, carrier_invoices) = $rate

Checks that this document’s rate matches the rate from the previous upload with the same id.