Skip to content
Talk to our solutions team

Rule API reference

This reference covers what a rule can call, and nothing else. If a name is not on these pages, rule text cannot reach it.

That boundary is the point of the section. The engine is a library, and most of its surface exists for the program that embeds it, constructing an engine, loading rule sets, reading a result object. None of that is available inside a when or a then. You write GRL; this is the GRL-visible API.

kis rules and rules.svc bind the same names, with one exception: bbox, the document surface, is loaded only by kis rules.

NameWhat it isReference
your factsEvery top-level key of the input, bound under its own nameWriting rules
inGuard-free reads of those facts, with defaults and dotted pathsin: reading facts
outThe output collector. What it holds is the result, and later rules read itout: writing results
findingsSeverity-graded validation results, returned beside outFindings
auditAppend-only decision trailFindings
actProposed writes to a data source, returned as actionsact
agendaagenda.Repeat(): the rule that calls it may fire againWriting rules
toConversion between the types a rule handlesto: conversion
stringsText: case, regex, phrase counting, line locationstrings: text
map, arrayCollections, since the language cannot index onemap and array
num, math, timeRanges, numbers in text, arithmetic and datesnum, math, time
name, date, addressSplitting a person’s name, finding dates in text, splitting a postal addressFunctions
vocabNamed phrase lists and lookup tablesvocab
logLog lines: Debug, Info, Warn, ErrorIncluded plugins
deliveryOutput shaping: ExplodeColumnIncluded plugins
bboxThe document surface, on a kis rules run that carries a documentbbox: documents

Two verbs are bound with no namespace:

CallEffect
Retract("RuleName")Removes another rule from the pool for the rest of this execution. A rule that fires is retracted automatically, so each fires at most once per run; retracting the rule itself is unnecessary
Complete()Ends the execution immediately, keeping everything written so far. No other rule fires

On a kis rules run, a document arrives as bbox, and everything a rule does with it starts at bbox.Doc(). rules.svc does not load documents.

bbox.Doc().Top(20).Has("INVOICE")
bbox.Doc().Right("Loan Amount").Currency()
TypeReached byReference
Docbbox.Doc(), and every scope call on itDocument
ValueA directional read, a cell, a coercionValues
Table, Rowbbox.Doc().Table(), .TableWith(text)Tables and forms
Rowsbbox.Doc().Rows(start, end)Tables and forms
Formbbox.Doc().Form(name)Tables and forms

Matching through this surface is fuzzy and case-insensitive by default. You do not configure it; you opt out with Exact() or MatchCase() when a near-miss would be wrong. See the Document API guide for why.

Every entry names what a rule gets back, because that is what decides what the call is good for:

ReturnsWhat a rule can do with it
bool, number, stringUse it directly, in a when or as an argument
DocKeep chaining scopes and verbs
ValueCoerce it, or ask whether it was found
Table / Row / Rows / FormKeep calling that type’s methods
A list or mapCount it with .Len(), pass it to a map, array or to call, or pass a map or rows straight to out.Set. GRL cannot index or iterate one, and a local variable cannot hold one
Two valuesNothing. The call loads, then aborts the execution with calling function <Fn> which returns multiple values

Every call a rule makes is checked when the rule set loads (kis rules check, kis rules --validate, rules.svc’s load): a method that does not exist, or the wrong number of arguments, is an error naming the rule and line, with a suggestion when one is close (strings has no method Trim (did you mean Join?)). A deprecated call loads with a warning naming its replacement.

What it does not catch, each of which aborts the execution when the rule is evaluated:

MistakeRun-time failureWrite instead
An integer literal where a float is takenreflect: Call using int64 as type float640.0, 10.0
A bare fact name the caller did not send, in any rule’s whennon existent key <name>in.Str("name", "") and the other in reads
Dot access on a map fact, order.Totalthis node identified as "order" is not referencing to an objectin.Double("order.Total", 0.0)
A call that returns two valuescalling function <Fn> which returns multiple valuesNothing: the call is not usable
Not documentedWhyWhere it is
Engine construction, rule-set loading, result objectsNot reachable from rule textThe library’s own source
Word boxes, lines, reading order, table detectionAnalysis that happens before your rule runsThe document model
hOCR ingest and the .bbox formatInput preparation, not a rule callOCR input
Fuzzy scoring internalsA property of the surface, not a knobThe Document API