3. Securing your Spec

data fields accept any value by default. If you send in a temperature of "banana", Lemma won't complain; it just won't match any numeric conditions. Constraints on data (or named types) restrict what values are valid and make your spec more precise.

The -> syntax defines constraints on a field. The editor below shows a spec that restricts the possible values for forecast to a fixed set, and sets bounds on temperature.

Constraints on data

You can attach -> constraint lines directly to a data field, as in the editor above. Lemma validates incoming consult data against those constraints before evaluating rules. For reusable bundles of constraints, you can also declare a named type and use it in data the same way you'd use text or scale.

The -> syntax

Each -> line adds a constraint. Available constraints depend on the base type:

  • options restricts a text field to a set of allowed string values
  • minimum and maximum bound a number or scale field
  • unit declares the measurement unit for a numeric type

Veto rules

A rule that starts with veto rejects the whole consultation unless it finds an accept. In the spec above, veto_outdoor_activity blocks the response entirely when the weather is bad, regardless of what the other rules say.

Veto rules are useful for hard constraints: legal requirements, safety checks, anything that must pass before a decision can be made.