> ## 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.

# Rating a product

> Write a filed rating plan as an RSL rater: a module whose entry function returns a premium, with its inputs, checks, tables, rounding and citations.

A **rater** is a module that rates one product. Its entry function takes the facts of one
policy and returns money: an amount on a grid, such as whole cents or whole dollars. A rater is a
[function](https://docs.canary.effectiveai.app/rsl/concepts/functions.md): values in, one value out. It reads the request and its own
tables only, so the same request always gets the same premium.

## Rater parts

Each part of a filed rating plan has one place in a rater:

| The filing holds | The rater holds | Read more |
| - | - | - |
| The facts a premium depends on | Typed inputs | [Values and types](https://docs.canary.effectiveai.app/rsl/concepts/values-and-types.md) |
| The risks the manual rates | Checks on inputs and records, each with a code | [Functions and checks](https://docs.canary.effectiveai.app/rsl/concepts/functions.md) |
| Rate tables and factors | Tables, often in CSV files, and constants | [Use a filed rate table](https://docs.canary.effectiveai.app/rsl/how-to/read-a-filed-table.md) |
| The rating algorithm | Named steps of arithmetic | [Functions and checks](https://docs.canary.effectiveai.app/rsl/concepts/functions.md) |
| Rounding rules | A `round` at each place the filing rounds | [Round a premium](https://docs.canary.effectiveai.app/rsl/how-to/round-a-premium.md) |
| The page that prints each number | A citation on each table, constant and rounding | [Evidence](https://docs.canary.effectiveai.app/rsl/concepts/evidence.md) |
| The premium | The outcome the entry returns | [Modules](https://docs.canary.effectiveai.app/rsl/concepts/modules.md) |

## Rater shape

The rater of [Write your first rater](https://docs.canary.effectiveai.app/rsl/tutorial/first-rater.md) rates a dwelling-fire policy.
Its premium step reads a rate table and rounds each peril premium to cents. It adds the fees and rounds the total to whole dollars:

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
step premium {
    base_rate[p: Peril]: Rate =
        lookup!(BaseRate, self.dwelling.protection_class).rate[p],
    peril_premium[p: Peril]: Premium [cite: manual:p8] =
        round(self.dwelling.coverage_a / 1000 * self.base_rate[p], 2, half_up),
    item_charge: Premium [cite: manual:p6] = sum(self.items as i, i.charge),
    premium: Premium [cite: manual:p9] =
        round(sum(Peril as p, self.peril_premium[p]) + self.item_charge + expense_fee, 0, half_up)
}
```

A check on an input refuses a request outside the risks that the manual rates. This one carries a code,
a message and the page it comes from:

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
protection_class: Num {precision: int}
    where self in [1, 10] [code: "PROTECTION-CLASS", message: "Protection class must be 1 to 10.", cite: manual:p4]
```

The rater names the value a caller reads:

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
RatingOutcomes = {
    premium: Policy.premium
}
```

## Guarantees

* Arithmetic is exact. A value changes only at a `round` that the rater writes.
* The rater reads each number of a request from its text, so `1000.005` stays `1000.005`. A number off its input's precision gets a refusal.
* A rater that passes `rslc check` gives a value for each request it accepts. Each lookup finds a row.
* A refused request gets the check's code, the path of the input and the message. [Refusals](https://docs.canary.effectiveai.app/rsl/reference/refusals.md) lists the fields.
* Each table, constant and rounding cites the page of its source document.

[What the check proves](https://docs.canary.effectiveai.app/rsl/concepts/guarantees.md) states each guarantee. The check proves the
rater is sound, and tests against the filing prove it is right.

## Requests and books

* Rate one request with Relativities: `Rater.load` reads the bundle that `rslc export` writes. [Write your first rater](https://docs.canary.effectiveai.app/rsl/tutorial/first-rater.md) shows each step.
* Rate a whole book: [Rate a book with a program](https://docs.canary.effectiveai.app/relativities/how-to/rate-a-book-with-a-program.md).
* Rate requests through the API: release the rater on Effective, then evaluate each request. [Programs on Effective](https://docs.canary.effectiveai.app/rsl/programs-on-effective.md) shows the flow.

Keep the `bundle_id` beside each premium you keep. It names the exact rater that gave the premium.

## Filing tests

A filing often prints rating examples. Rate each one and compare the premiums.

* [Test a rater](https://docs.canary.effectiveai.app/rsl/how-to/test-a-rater.md) compares independent premiums and checks the boundaries of each rule.
* [Package a program](https://docs.canary.effectiveai.app/relativities/how-to/package-a-program.md) keeps the examples in the bundle, and `check` rates them again after each change.
* [Validate a program](https://docs.canary.effectiveai.app/relativities/how-to/validate-a-program.md) lists the evidence to keep.

A reviewer still checks the extracted rates and the interpreted rules against the filing. After a new
release, rate the examples again and compare each premium and `bundle_id`.

## Next steps

* [Write your first rater](https://docs.canary.effectiveai.app/rsl/tutorial/first-rater.md) builds this rater from a rating manual.
* [Underwriting a submission](https://docs.canary.effectiveai.app/rsl/uses/underwriting.md) puts a rater behind a guideline.


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