Skip to content

Learn · Rulebooks

Write a logic rulebook

The document shape, the four parts of a check, and what happens when one matches.

Checked against the product on · written for people writing code

A logic rulebook is one document holding an ordered list of checks. Each check has an id, a match, and what to do when the match holds.

The parts of one check.
PartWhat it holdsRequired
idA name for this check, unique in the rulebook. It appears in the logbook when the check fires.Yes
matchThe test. One check, or several joined with all / any / none / one-of.Yes
build-upWeight, half-life and the bands that turn repeated weak matches into an escalation.No
on a matchWhat to do: write it down, gate the action, or raise a warning label.Yes
on no matchThe same, for the times the check does not hold.No

Build-up catches the quiet one

A plain threshold catches the loud event and misses the quiet recurring one: the link that drops for two seconds every hour, the account moving money in amounts each under every limit.

Build-up handles those. Each watched thing carries a score for the check. A match adds weight; between matches the score fades on the half-life you set. Crossing a band decides who hears about it: write it down, gate the action, or bring in a person.

A build-up block, read in plain words.
SettingExampleWhat it means
weight1.0How much one match adds to the score.
half-life30mHow long the score takes to fade by half with no further match.
band: write it down3At a score of 3, the logbook gets an entry.
band: gate the action6At 6, the thing in flight is held or stopped.
band: bring in a person10At 10, a person is asked to look.

Write and publish one

  1. Write the checks as one document, each with an id and a match.

    Order matters when two checks could both apply. The first match wins.

  2. Publish the version.

    The whole document is checked at this moment. A bad pattern, a check nested too deep, or too many checks fails here.

  3. Install it into the work area that should run it.

    Install requires the same account that wrote it.

  4. Watch the logbook for the ids you named.

    Every firing writes one entry naming the check that fired.

Watch out. A rulebook that fails its check at publish is refused with the reason. This is on purpose: a bad check that failed quietly while events flowed past would leave you believing you were covered.
POST/v1/logic-canons/{id}/versions

Publish a version of a logic rulebook. The document is compiled and validated here; an invalid one is refused with the reason.

idstringrequiredThe logic rulebook this version belongs to.