Math Operations
Performs mathematical calculations or aggregations on data.
Aggregates the values array of the incoming payload (sum, average, minimum, maximum) or returns a value computed by an Expression Engine {{ }}, as { result }.
This operator provides standard arithmetic and aggregation functions. It does not use JSONata: in expr mode the result is the value already resolved by the Sommatic AI Expression Engine.
Operations:
- Sum/Avg/Min/Max: Aggregations over
values(an array of numbers in the input payload). Non-numeric entries are ignored; an empty list returns 0. - Advanced (Expr): A
{{ }}JavaScript expression (e.g.{{ Math.round($json.price * 1.2 * 100) / 100 }}). The resolved value is returned asresultwithout further evaluation.
Use Cases:
- Calculating the total value of items in a shopping cart.
- Finding the highest bid in an auction list.
- Computing tax percentages.
How it works
- Resolves the config;
opdefaults tosum.{{ }}inexpressionare evaluated by the Expression Engine (JavaScript, 100 ms limit). expr:resultis the resolvedexpressionas is, of any type. JSONata is not used.sum,avg,min,max: readvaluesfrom the incoming payload (not configurable). A string fails; each entry is converted withNumber()andNaNentries are dropped; an empty list gives 0.- Returns
{ result }throughout; the incoming payload is not passed through.
In a workflow
The node as it appears in a workflow file (draft_nodes[]), and the envelope of a successful run.
{
"node_id": "node-cart-total",
"label": "Cart total",
"operator_slug": "data.math",
"operator_version": "1.0.0",
"config": {
"op": "expr",
"expression": "{{ Math.round(_.sum($json.items.map(item => item.price * item.qty)) * 100) / 100 }}"
}
}{
"ok": true,
"data": {
"result": 42.5
},
"port": "out"
}Configuration
-
opstring Optional -
expressionstring Optional Accepts expressions -
Expression Engine calculation wrapped in {{ }} (required if op is "expr"), e.g. {{ $json.price * 1.2 }}. JSONata is not supported.
Its configuration shows the shared execution settings, but this node does not apply retries (retryOnFail, maxTries) yet. continueOnFail is not applied by any node.
Behaviour in the code
What the implementation does with these keys beyond what the schema says.
-
expression - Used only with
opexpr. Without{{ }}the literal text is returned. If a whole-value{{ }}throws, the resolver keeps the original text, soresultis the{{ ... }}string and the node still leaves throughout.
Output ports
out default The calculation finished.
{
"result": 42.5
}error Unknown op, or values cannot be read as a list.
{
"ok": false,
"errors": [
"Math Error: Values must be an array for aggregation"
],
"port": "error"
}In expressions
What a later node can read from this node's output with $("Math Operations").item.json.<path> (write your node's label instead of Math Operations). Editor marks the paths the workflow editor suggests under Previous Nodes (the output contract); Worker marks the paths the worker really returns through out, from the output shown in Ports.
| Expression | Editor | Worker |
|---|---|---|
$("Math Operations").item.json.resultCalculation result. |
Errors
| Message | Port | Cause and fix |
|---|---|---|
Math Error: Unknown op: <op> | error | op is not sum, avg, min, max or expr. |
Math Error: Values must be an array for aggregation | error | values in the payload is a string. |
Math Error: (values || []).map is not a function | error | values is a number, an object or true. |
Input contract
-
valuesarray<number> Optional -
List of numbers (for aggregations).
-
payloadobject Optional -
Context for custom expressions.
Output contract
-
resultnumber Optional -
Calculation result.
Contracts (JSON Schema)
The definition exactly as the orchestrator declares it. All is the whole *.definition.js; compare it with the sections above to spot differences between the documentation and the schema. Use it to validate a node before you publish.
{
"slug": "data.math",
"name": "Math Operations",
"category": "data",
"version": "1.0.0",
"description": "Performs mathematical calculations or aggregations on data.\n\n This operator provides standard arithmetic and aggregation functions. It does not use JSONata: in `expr` mode the result is the value already resolved by the Sommatic AI Expression Engine.\n\n **Operations:**\n - **Sum/Avg/Min/Max:** Aggregations over `values` (an array of numbers in the input payload). Non-numeric entries are ignored; an empty list returns 0.\n - **Advanced (Expr):** A `{{ }}` JavaScript expression (e.g. `{{ Math.round($json.price * 1.2 * 100) / 100 }}`). The resolved value is returned as `result` without further evaluation.\n\n **Use Cases:**\n - Calculating the total value of items in a shopping cart.\n - Finding the highest bid in an auction list.\n - Computing tax percentages.",
"capabilities": [
"math",
"calculation",
"aggregation"
],
"config_schema": {
"type": "object",
"properties": {
"op": {
"type": "string",
"enum": [
"sum",
"avg",
"min",
"max",
"expr"
],
"default": "sum",
"title": "Operation"
},
"expression": {
"type": "string",
"format": "expression",
"title": "Custom Expression",
"description": "Expression Engine calculation wrapped in {{ }} (required if op is \"expr\"), e.g. {{ $json.price * 1.2 }}. JSONata is not supported."
},
"execution": {
"type": "object",
"title": "Execution Settings",
"properties": {
"alwaysOutputData": {
"type": "boolean",
"title": "Always Output Data",
"description": "Always output data, even on error (if configured).",
"default": false
},
"retryOnFail": {
"type": "boolean",
"title": "Retry On Fail",
"description": "Retry the execution if it fails.",
"default": false
},
"maxTries": {
"type": "integer",
"title": "Max Retries",
"description": "Number of retries.",
"default": 3,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"waitBetweenTries": {
"type": "integer",
"title": "Wait Between Retries (ms)",
"default": 1000,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"continueOnFail": {
"type": "boolean",
"title": "Continue On Fail",
"description": "Do not crash workflow on error.",
"default": false
},
"timeout_ms": {
"type": "integer",
"title": "Timeout (ms)",
"description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
"default": 300000
}
}
}
}
},
"input_contract_schema": {
"type": "object",
"properties": {
"values": {
"type": "array",
"items": {
"type": "number"
},
"description": "List of numbers (for aggregations)."
},
"payload": {
"type": "object",
"description": "Context for custom expressions."
}
}
},
"output_contract_schema": {
"type": "object",
"properties": {
"result": {
"type": "number",
"description": "Calculation result."
}
}
},
"ports": [
{
"port_id": "out",
"label": "Result",
"is_default": true
},
{
"port_id": "error",
"label": "Error"
}
],
"execution_mode": "sync",
"tags": [
"math",
"calc",
"sum",
"stats"
],
"is_stateful": false,
"publisher": {
"identity": "org_link_loom",
"profile": {
"name": "Link Loom",
"verified": true,
"url": "https://me.veripass.com/link-loom",
"logo_url": null
}
}
}{
"type": "object",
"properties": {
"op": {
"type": "string",
"enum": [
"sum",
"avg",
"min",
"max",
"expr"
],
"default": "sum",
"title": "Operation"
},
"expression": {
"type": "string",
"format": "expression",
"title": "Custom Expression",
"description": "Expression Engine calculation wrapped in {{ }} (required if op is \"expr\"), e.g. {{ $json.price * 1.2 }}. JSONata is not supported."
},
"execution": {
"type": "object",
"title": "Execution Settings",
"properties": {
"alwaysOutputData": {
"type": "boolean",
"title": "Always Output Data",
"description": "Always output data, even on error (if configured).",
"default": false
},
"retryOnFail": {
"type": "boolean",
"title": "Retry On Fail",
"description": "Retry the execution if it fails.",
"default": false
},
"maxTries": {
"type": "integer",
"title": "Max Retries",
"description": "Number of retries.",
"default": 3,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"waitBetweenTries": {
"type": "integer",
"title": "Wait Between Retries (ms)",
"default": 1000,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"continueOnFail": {
"type": "boolean",
"title": "Continue On Fail",
"description": "Do not crash workflow on error.",
"default": false
},
"timeout_ms": {
"type": "integer",
"title": "Timeout (ms)",
"description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
"default": 300000
}
}
}
}
}{
"type": "object",
"properties": {
"values": {
"type": "array",
"items": {
"type": "number"
},
"description": "List of numbers (for aggregations)."
},
"payload": {
"type": "object",
"description": "Context for custom expressions."
}
}
}{
"type": "object",
"properties": {
"result": {
"type": "number",
"description": "Calculation result."
}
}
}[
{
"port_id": "out",
"label": "Result",
"is_default": true
},
{
"port_id": "error",
"label": "Error"
}
]Execution
- Execution
sync- Stateful
- No
- Retries (
retryOnFail) - No
- Capabilities
mathcalculationaggregation- Tags
mathcalcsumstats
Notes and limits
null, empty strings and booleans invaluesconvert to 0 or 1 and are counted.- To aggregate another field, shape it first (for example a
data.transformthat returns{ "values": items.price }) or useexprwith{{ _.sum($json.items.map(item => item.price)) }}. - When the envelope has no
data(ordatais falsy), the engine stores the whole envelope as the node output: onerrorthe next node receives{ ok: false, errors: [...], port: "error" }as its payload.
Reviewed against the orchestrator code · 31e874b · 2026-11-26