What Operators Are Supported by Probe's Expression Engine? Complete Syntax Reference
Probe's expression engine supports arithmetic, comparison, logical, ternary, and null‑coalescing operators inherited from the expr‑lang/expr library, alongside custom functions like random_int() and match_json().
Probe is a lightweight workflow automation tool that evaluates dynamic expressions through a sandboxed engine. The system delegates expression parsing to the proven expr‑lang/expr library while layering additional safety controls and domain-specific functions on top. Understanding which operators are available helps you write precise conditional logic and variable transformations in your workflow definitions.
Arithmetic and Comparison Operators
Probe inherits standard mathematical and equality operators from the underlying expr library. These work on numeric types and strings where applicable.
Arithmetic operators include:
+for addition-for subtraction*for multiplication/for division%for modulo
Comparison operators include:
==for equality!=for not equal<for less than<=for less or equal>for greater than>=for greater or equal
In expr_test.go, the TestEvalOrEvalTemplate function demonstrates basic arithmetic: {{ 1 + 1 }} evaluates to 2. For HTTP status checks, you might use {{ status >= 200 && status < 300 }} as shown in TestEval.
Logical and Conditional Operators
Beyond basic math, Probe supports boolean logic and conditional evaluation.
Logical operators:
&&for logical AND||for logical OR!for logical NOT
Conditional operators:
- Ternary:
condition ? trueVal : falseValfor inline if‑else logic - Null‑coalescing:
??for providing default values when the left side is nil or empty
The test suite in expr_test.go validates these through TestEval and TestEvalTemplate. For example, {{ res.code == 200 && res.body.success }} combines comparison with logical AND, while {{ env.URL == 'localhost' ? 'http://localhost:3000' : env.URL }} demonstrates ternary selection.
Domain‑Specific Functions
Probe extends the base engine with custom functions defined in funcs.go. These are registered in expr.go and available alongside standard operators.
Utility functions:
random_int(max)– Returns random integer from 0 to max‑1random_str(len)– Generates random string of specified lengthunixtime()– Returns current Unix timestamp
Data processing:
match_json(src, tgt)– Compares two JSON structuresdiff_json(src, tgt)– Returns differences between JSON structuresencode_base64(str)anddecode_base64(str)– Base64 transformationsparse_int(val)andparse_float(val)– Type conversions
These functions are tested in TestNewCustomFunctions and TestCustomFunctions within expr_test.go.
Security Architecture and Limitations
The engine deliberately restricts functionality to maintain sandbox safety. According to the implementation in expr.go, Probe disables all built‑in functions via ex.DisableBuiltin("all") and re‑enables only the whitelisted custom functions listed above.
Safety mechanisms include:
- Expression length limit: 1,000,000 characters (
maxExpressionLength) - Evaluation timeout: 5 seconds default (
evaluationTimeout) - Environment filtering: The
createSafeEnvironmentfunction blocks dangerous keys likeSECRETandPATHthrough theisSafeEnvKeyhelper
These safeguards are exercised in TestSecurityValidation and TestSafeEnvironment in the test suite.
Practical Usage Examples
When writing Probe workflows, you can combine operators and functions in templates or direct evaluations.
Arithmetic with variables:
env := map[string]any{"count": 10}
result, _ := expr.Eval("count * 2 + 5", env) // → 25
Conditional routing:
env := map[string]any{"status": 404}
isNotFound, _ := expr.Eval("status == 404", env) // → true
Template with null‑coalescing:
env := map[string]any{"env": map[string]any{"API_URL": nil}}
url, _ := expr.EvalTemplate("{{ env.API_URL ?? 'http://localhost:8080' }}", env)
// → "http://localhost:8080"
Combining functions and operators:
// Generate random delay between 0-9 seconds
delay, _ := expr.Eval("random_int(10) * 1000", nil)
Summary
- Probe delegates expression evaluation to the expr‑lang/expr library, supporting arithmetic (
+,-,*,/,%), comparison (==,!=,<,<=,>,>=), and logical (&&,||,!) operators. - Ternary (
? :) and null‑coalescing (??) operators enable conditional logic and safe fallback values. - Nine custom functions including
random_int(),match_json(), andencode_base64()extend the base operator set for workflow-specific tasks. - Security controls in
expr.golimit expression length, execution time, and environment access while disabling all non‑whitelisted built‑ins.
Frequently Asked Questions
Can I use regular expressions in Probe expressions?
No, the expr‑lang/expr library used by Probe does not expose regular expression operators in its default grammar. For pattern matching, use the match_json() function to compare structures or preprocess values in your workflow steps before evaluation.
What happens if an expression evaluates for longer than 5 seconds?
Probe forcibly terminates the evaluation and returns an error. The evaluationTimeout constant in expr.go sets a hard limit of 5 seconds to prevent runaway computations from blocking workflow execution.
Are there any operator precedence rules I should follow?
Yes, standard mathematical precedence applies: multiplication and division evaluate before addition and subtraction, and comparison operators evaluate after arithmetic. Parentheses can override precedence. Logical operators follow the conventional order where ! binds tightest, then &&, then ||.
Why can't I access environment variables like PATH or SECRET in expressions?
Probe filters environment access through the isSafeEnvKey function in expr.go to prevent information leakage. Keys containing sensitive patterns like SECRET, PATH, or TOKEN are blocked by createSafeEnvironment before evaluation begins.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →