Skip to content
Talk to our solutions team

Built-in functions

This is the complete call surface of a rule. Everything a when or then can invoke is either an unqualified built-in, a method on a value, or a method on one of the bindings below. Nothing else is reachable. There is no import, no user-defined function, and no way to add one from a rule file.

Five plugins are registered on every engine, util, log, findings, delivery and vocab, so the bindings they contribute are always there. bbox is registered on request: kis rules registers it when a run has document input. rules.svc serves no documents.

BindingHoldsBound
infact reader, with defaults and dotted pathsevery execution
outthe result collector returned to the callerevery execution
findingsseverity-graded validation issuesevery execution
audittimestamped decision trailevery execution
toconversion between the types a rule handlesevery execution
actproposed writes to recordsevery execution
agendaagenda.Repeat(): keeps the firing rule on the agenda for another cycleevery execution
num strings time math map arrayhelper librariesevery execution
namesplits a person’s name: name.First(v), name.Last(v), name.Parse(v)every execution
datefinds dates inside text: date.First(v), date.Last(v), date.Nth(v, n)every execution
addresssplits a postal address: address.City(v), address.Zip(v), address.Parse(v)every execution
utilnamespace holder; carries no helper functionsevery execution
logstructured loggerevery execution
vocabnamed phrase lists and lookup tablesevery execution
deliveryoutput shapingevery execution
bboxdocuments, and bbox.Doc()kis rules executions that supply documents

bbox fails hard rather than degrading: naming it when no document was supplied aborts the whole execution with got non existent key bbox. Guard a document-dependent ruleset at the top rather than per rule.

These constraints decide whether a signature in the tables below is usable, and they are the reason some functions are marked not callable.

ConstraintConsequence
Every call on a binding is checked when the rule set loadsA method that does not exist, or the wrong number of arguments, is an error naming the rule and line: rules.svc and kis rules check refuse the set, kis rules --validate lists it. Argument types are not checked; see Validating a rule set
Integer literals are int64, float literals are float64, with no coercionA parameter typed plain int, float32 or a named integer type cannot be satisfied. math.Min(10, 20) loads, then panics when it runs; write math.Min(10.0, 20.0)
Methods returning (value, error) are rejected by the dispatcherout.JSON(), audit.JSON() and findings.JSON() load but fail at evaluation
There is no array, map or struct literal in the grammarA collection argument must be the direct result of another call, never a local variable
Any evaluation error aborts the whole executionrules.svc returns what was written before it under meta.partial; kis rules reports the error and no result

Chain a collection straight into the call that consumes it, or stage it with out.Set and read it back:

// WRONG - `parts` is a local variable holding a list
parts = strings.Split(in.Str("codes", ""), ",");
out.Set("first", parts[0]);
// CORRECT - index the call directly
out.Set("first", strings.Split(in.Str("codes", ""), ",")[0]);
// CORRECT - stage a list of records with out.Set, read it back, then drop it from the result
out.Set("rows", in.Rows("lines"));
out.Set("row", array.FindRowBy(out.Value("rows").Rows(), "description", "homeowner"));
out.Delete("rows");

Called with no binding prefix. These come from the rule engine itself.

SignatureBehaviour
Retract(ruleName)Takes the named rule off the agenda for the rest of this execution. Reset on the next execution. A rule already leaves the agenda when it fires, so a rule never needs to retract itself
Complete()Hard stop. The engine exits the cycle loop immediately; lower-salience rules never run
Forget(snippet) / Changed(variableName)Clear the engine’s cache of evaluated expressions. Not needed: a write to out is already seen by later rules. Kept so existing rules load
Now()Current time
MakeTime(year, month, day, hour, minute, second)Builds a time value in the local zone
GetTimeYear(t)Year component. Also GetTimeMonth, GetTimeDay, GetTimeHour, GetTimeMinute, GetTimeSecond
IsTimeBefore(t, before)Ordering test. Also IsTimeAfter(t, after)
TimeFormat(t, layout)Formats with a layout string
StringContains(str, substr)Substring test
ContainsStr(list, v)Membership test over a list produced by another call
IsZero(v)Zero-value test for time, pointer, string and numeric kinds. A bool always reports false
IsNil(v)Nil test. Panics on a non-nilable value such as a string
Log(text)Writes to the engine’s own logger. Unrelated to the log binding
LogFormat(format, v)Formatted engine log line
Max(vals ...)Variadic maximum. Float literals only. Also Min
Round(x)Rounds to a whole number. One argument: not the two-argument math.Round

The standard maths library is also wrapped unqualified: Abs, Acos, Acosh, Asin, Asinh, Atan, Atan2, Atanh, Cbrt, Ceil, Copysign, Cos, Cosh, Dim, Erf, Erfc, Erfcinv, Erfinv, Exp, Exp2, Expm1, Float64bits, Float64frombits, Floor, Gamma, Hypot, Ilogb, IsInf, IsNaN, J0, J1, Jn, Ldexp, MathLog, Log10, Log1p, Log2, Logb, Mod, NaN, Pow, Pow10, Remainder, RoundToEven, Signbit, Sin, Sinh, Sqrt, Tan, Tanh, Trunc. They take and return float64, except that Ilogb returns int, IsInf/IsNaN/Signbit return bool, Float64bits returns uint64, and IsInf, Jn, Ldexp and Pow10 take an int64 where the Go original takes int. Float64frombits is not callable, its parameter is uint64 and a rule literal is int64. MathLog is the natural logarithm, the name Log is taken by the engine logger.

Any string-typed expression carries these directly, without a binding prefix.

ReceiverMethods
stringIn(...), Compare(s), Contains(s), Count(s), HasPrefix(s), HasSuffix(s), Index(s), LastIndex(s), Repeat(n), Replace(old, new), Split(sep), ToLower(), ToUpper(), Trim(), Len(), MatchString(pattern)
array or sliceLen(), Append(v): appends in place, returns nothing
mapLen()
number or boolnone: calling any method on a numeric or boolean value is an error

"gold".In("gold", "platinum") is the idiomatic membership test and needs no helper.

Each is documented in full in the API reference: every method with its parameters and a worked rule. This page covers what is true across them; the reference covers each one.

BindingHoldsReference
inGuard-free reads of the input factsin: reading facts
outThe result collectorout: writing results
actProposed writes to recordsact: proposed writes
findingsSeverity-graded validation resultsFindings
auditThe decision trailFindings
bboxDocuments, and bbox.Doc()bbox: documents
toConversion between typesto: conversion
stringsText, regex, phrase countingstrings: text
map, arrayCollectionsmap and array
num, math, timeArithmetic and datesnum, math, time
vocabNamed phrase lists and tablesvocab
logDebug, Info, Warn, ErrorIncluded plugins
deliveryOutput shapingIncluded plugins

The operation vocabulary bbox.PostprocessRows takes.

OperationEffect
trimTrims leading and trailing whitespace
upperUpper case
lowerLower case
normalize_spacesCollapses every run of whitespace to a single space, then trims
trim_currencyTrims, removes every $ and ,, trims again
ExtractRegex("pattern", "default")Keeps the pattern’s capture groups, joined, or the whole match when it has none; the default when it does not match

Chain by calling PostprocessRows again. Each call reads the rows the previous one returned.

Check the operation name against the table above before relying on it: a name outside this set leaves the value untouched rather than reporting itself, so the symptom is output that did not change.