> ## Documentation Index
> Fetch the complete documentation index at: https://docs.canary.effectiveai.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Functions and checks

> A function takes values and gives one value. A check is a condition on its input that refuses a call.

A **function** takes values and gives one value.
It reads only its arguments, its constants and its tables.
So the same arguments give the same value on every machine, every time.

Rate tables, calculations and rounding live in functions.
A rating calculation, a refund and an eligibility test are each a function.

## Function parts

In RSL 0.4.2, a file with `component: rater` states one function. A file that leaves `component` out does too:

| Part of the function | Written as |
| - | - |
| Its arguments | The `inputs` of the root record |
| Its named values | The calculations in each `step` |
| Its data | `Constants` and `Tables` |
| Its result | `RatingOutcomes`: the values that a caller reads by name |

This file is the smallest function that passes the check. It takes a payroll and gives a premium:

> [accordion] minimal/rater.rsl
>
> ```rsl minimal/rater.rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
> spec {
>     rsl: "0.4.1",
>     carrier: "Example Mutual",
>     state: AZ,
>     product: "Staffing Liability",
>     effective_date: 2026-01-01
> }
>
> Sources = {
>     manual: Source = {
>         artifact: artifact("00000000-0000-4000-8000-000000000000"),
>         kind: pdf
>     }
> }
>
> Constants = {
>     rate_per_1000 [cite: manual:p3] = 2
> }
>
> Records = {
>     Policy = {
>         inputs {
>             payroll: Num {precision: int} where self in [0, 100000000]
>         },
>         step rating {
>             premium: Premium [cite: manual:p3] = round(self.payroll / 1000 * rate_per_1000, 2, half_up)
>         }
>     }
> }
>
> RatingOutcomes = {
>     premium: Policy.premium
> }
> ```

Each calculation reads inputs, constants, tables and other calculations.
RSL orders the calculations by what each one reads, so the order in the file is free.

## Checks

A **check** is a condition on an input, a list or a record.
A call whose input breaks a check gets a refusal in place of a value.
This check of a staffing rating function refuses a payroll under \$1,000:

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
    } where self.payroll >= 1000 [code: "PAYROLL_BELOW_MINIMUM", message: "The payroll must be at least $1,000.", cite: rules:p1]
```

| Check | A call that breaks it gets |
| - | - |
| With a `code` | A business refusal with the code, the message and the citation |
| A plain check, such as a range | An input refusal, with a code such as `INPUT-RANGE` |

The function checks every input before it calculates.
Once each check passes, every calculation gives a value.
A process that calls the function reads a refusal with a code as the `Declined` case of the result.

## Related

* [Records](https://docs.canary.effectiveai.app/rsl/reference/language.md#records), [Steps and calculations](https://docs.canary.effectiveai.app/rsl/reference/language.md#steps-and-calculations) and [Rules](https://docs.canary.effectiveai.app/rsl/reference/language.md#rules) in the language reference give each form.
* [Refusals](https://docs.canary.effectiveai.app/rsl/reference/refusals.md) lists the fields of a refusal and the order of the checks.
* [Modules](https://docs.canary.effectiveai.app/rsl/concepts/modules.md) shows how a process calls a function.
* [Guarantees](https://docs.canary.effectiveai.app/rsl/concepts/guarantees.md) states what the check proves about a function.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.