Overview
When extracting structured data from documents, you often need values that aren’t explicitly stated but can be computed from other fields. For example:- Line item totals:
quantity * unit_price - Invoice totals: Sum of all line item totals
- Reconciliation checks: Verify that computed totals match stated totals
- Conditional values: Apply different logic based on field values
- Arithmetic operations:
+,-,*,/ - Mathematical functions:
ABS,SQRT,LOG,POW - Aggregation functions:
SUM,AVERAGE,MIN,MAX,COUNT - Array operations:
FILTER,FLATTEN,LOOKUP,MATCH - Logical operations:
AND,OR,NOT,IF - Comparison operators:
=,!=,>,>=,<,<= - String operations:
CONCAT
Defining Computed Fields
Computed fields are defined in the project section of the dashboard (schema editor/functions).Expression Syntax
Paths and Field References
Use dot notation to reference fields in your extracted data:| Concept | Syntax Example | Description |
|---|---|---|
| Field path | order.total | Field total inside object order |
| Array field | transactions | Array of transaction objects |
| Wildcard element | transactions.* | ”Each element” of transactions |
| Field per element | transactions.*.amount | amount field for every element in transactions |
Wildcards for Arrays
When working with arrays, use* to reference each element:
Arithmetic Operators
All arithmetic operators work on single values (scalars) and arrays (element-wise).| Operator | Syntax | Description | Example |
|---|---|---|---|
| Add | a + b | Add numbers | price + tax |
| Subtract | a - b | Subtract b from a | total - discount |
| Multiply | a * b | Multiply numbers | quantity * unit_price |
| Divide | a / b | Divide a by b (null if b = 0) | distance / time |
Mathematical Functions
| Function | Syntax | Description | Example |
|---|---|---|---|
| ABS | ABS(x) | Absolute value | ABS(-10) → 10 |
| SQRT | SQRT(x) | Square root (x must be non-negative) | SQRT(25) → 5 |
| LOG | LOG(x) or LOG(x, base) | Natural or custom-base logarithm | LOG(100, 10) → 2 |
| POW | POW(base, exponent) | Raise base to exponent power | POW(2, 3) → 8 |
Aggregation Functions
Aggregation functions reduce arrays to single values.| Function | Syntax | Description | Example |
|---|---|---|---|
| SUM | SUM(array, "field") | Sum all values | SUM(items, "price") |
| AVERAGE | AVERAGE(array, "field") | Arithmetic mean | AVERAGE(scores, "points") |
| MIN | MIN(array, "field") | Smallest value | MIN(items, "price") |
| MAX | MAX(array, "field") | Largest value | MAX(items, "rating") |
| COUNT | COUNT(array, value) | Count occurrences | COUNT(tasks.*.status, "done") |
Array Functions
| Function | Syntax | Description | Example |
|---|---|---|---|
| FILTER | FILTER(array, "field", comparator, value) | Keep elements matching condition | FILTER(items, "active", "=", true) |
| FLATTEN | FLATTEN(nestedArray) or FLATTEN(array, "field") | Merge nested arrays into one | FLATTEN(groups, "items") |
| LOOKUP | LOOKUP(array, "field", comparator, value, [proj]) | Find first match, optionally project | LOOKUP(users, "id", "=", 5, "name") |
| MATCH | MATCH(array, "field", comparator, value) | Get index of first match (-1 if none) | MATCH(items, "status", "=", "pending") |
FILTER
Keep only elements that satisfy a condition. Comparators:"=", "!=", ">", ">=", "<", "<=", "contains"
FLATTEN
Merge nested arrays into a single flat array.LOOKUP
Find the first matching element in an array.MATCH
Get the index (position) of the first matching element.Comparison Operators
| Operator | Syntax | Function Form | Description | Example |
|---|---|---|---|---|
| Equal | a = b, a == b | EQ(a, b) | True if equal | status = "active" |
| Not Equal | a != b | — | True if different | role != "admin" |
| Greater | a > b | GT(a, b) | True if a > b | price > 100 |
| Greater/Equal | a >= b | GTE(a, b) | True if a >= b | quantity >= 10 |
| Less | a < b | LT(a, b) | True if a < b | age < 18 |
| Less/Equal | a <= b | LTE(a, b) | True if a <= b | score <= 100 |
Logical Operators
| Function | Syntax | Description | Example |
|---|---|---|---|
| AND | AND(cond1, cond2, ...) | True if all conditions true | AND(user.active, user.verified) |
| OR | OR(cond1, cond2, ...) | True if any condition true | OR(priority = "high", overdue) |
| NOT | NOT(cond) or !cond | Invert boolean value | NOT(user.active) or !verified |
Conditional Logic (IF)
TheIF function returns different values based on a condition.
Syntax: IF(condition, value_if_true, value_if_false)
IF returns an array of results:
String Functions
| Function | Syntax | Description | Example |
|---|---|---|---|
| CONCAT | CONCAT(part1, part2, ..., partN) | Join values into a string | CONCAT("Hello ", name, "!") → “Hello Alice!” |
Null Handling
| Situation | Behavior |
|---|---|
Numeric op with null | Treated as 0 (e.g., 5 + null → 5) |
Logical op with null | Treated as false |
| Missing field | Returns null; use IF for safe defaults |
Real-World Examples
Example 1: Invoice Reconciliation
Verify that the sum of all property totals matches the check amount, within 1% tolerance.SUM(properties, "total_property_value")— Sum all property totals- check.amount— Subtract the check amountABS(...)— Get absolute difference (error)<= 0.01 * check.amount— Check if error is within 1%
Example 2: Filtered Aggregation
Sum only deposits from a transaction list:FILTER(transactions, "type", "=", "deposit")— Get only deposit transactionsSUM(..., "amount")— Sum their amounts
Example 3: Line Item Validation
For each line item, check ifowner_value matches computed value (within 1%):
- Skip validation for non-positive values (taxes, deductions)
- Compute expected value:
property_value * distribution_interest - Compare to actual
owner_valuewith 1% tolerance
Example 4: Nested Array Aggregation
Sum values across all nested arrays:FLATTEN(orders, "items")— Collect all items from all ordersSUM(..., "price")— Sum all prices
Example 5: Conditional Labeling
Categorize orders by size:Best Practices
1. Use Field Projection Syntax
PreferSUM(items, "price") over SUM(items.*.price) for clarity.
2. Handle Nulls Explicitly
3. Use Tolerance for Comparisons
Floating-point arithmetic can cause tiny differences. Use tolerance checks:4. Build Complex Expressions Incrementally
Define intermediate computed fields for readability:5. Use FILTER for Conditional Aggregation
Common Patterns
Header vs. Detail Reconciliation
Cross-Reference Validation
Conditional Processing
Aggregate with Multiple Conditions
Quick Reference
Arithmetic
| Operation | Example | Result |
|---|---|---|
| Add | 5 + 3 | 8 |
| Subtract | 10 - 4 | 6 |
| Multiply | 6 * 7 | 42 |
| Divide | 15 / 3 | 5 |
Math Functions
| Function | Example | Result |
|---|---|---|
| ABS | ABS(-10) | 10 |
| SQRT | SQRT(16) | 4 |
| POW | POW(2, 3) | 8 |
| LOG | LOG(100, 10) | 2 |
Aggregation
| Function | Example | Description |
|---|---|---|
| SUM | SUM(items, "price") | Total of all prices |
| AVERAGE | AVERAGE(scores, "value") | Mean of all values |
| MIN | MIN(items, "price") | Lowest price |
| MAX | MAX(items, "rating") | Highest rating |
| COUNT | COUNT(tasks.*.status, "done") | Count of “done” |
Array Functions
| Function | Example | Description |
|---|---|---|
| FILTER | FILTER(items, "active", "=", true) | Keep active items |
| FLATTEN | FLATTEN(orders, "items") | Merge all items |
| LOOKUP | LOOKUP(users, "id", "=", 5) | Find user by id |
| MATCH | MATCH(items, "status", "=", "pending") | Index of first match |
Comparators for Array Functions
| Comparator | Meaning | Example |
|---|---|---|
"=" | Equal | FILTER(users, "role", "=", "admin") |
"!=" | Not equal | FILTER(users, "role", "!=", "admin") |
">" | Greater than | FILTER(items, "price", ">", 100) |
">=" | Greater or equal | FILTER(orders, "total", ">=", 1000) |
"<" | Less than | FILTER(items, "priority", "<", 3) |
"<=" | Less or equal | FILTER(scores, "value", "<=", 50) |
"contains" | Substring match | FILTER(products, "name", "contains", "Pro") |
Go Further
- Extraction - Learn how to extract structured data
- Reasoning - Add step-by-step reasoning for complex calculations
- Schema - Design your extraction schemas