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

# Rate one manual in several states

> Keep a countrywide manual in one rater, and write a state file for each state that states only what its exception pages change.

[Install Relativities](https://docs.effectiveai.app/relativities/setup.md) before running the synthetic examples.

A carrier files one countrywide manual and, for each state, exception pages that change some of its rates and rules.
Keep the countrywide manual in one rater. Write a **state file** for each state: it names that rater as its base and states only the changes.

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
extends "base.rsl"
```

The example rates pet accident and illness for the synthetic carrier Example Mutual, in Texas and in California.
Save the files below in a folder `pet-states`.

## Keep the countrywide manual in one rater

Save the countrywide rater as `pet-states/base.rsl`, with its four tables:

> [accordion] Complete example: pet-states/base.rsl
>
> ```rsl pet-states/base.rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
> # Example Mutual, pet accident and illness: the countrywide manual.
> # Each state file in this folder extends this base and states only what its
> # exception pages change.
>
> spec {
>     rsl: "0.4.1",
>     carrier: "Example Mutual",
>     state: AZ,
>     product: "Pet Accident and Illness",
>     version: "1.0.0",
>     effective_date: 2026-05-01
> }
>
> Sources = {
>     countrywide: Source = {
>         artifact: artifact("00000000-0000-4000-8000-000000000401"),
>         kind: pdf
>     }
> }
>
> Types = {
>     PetType = {
>         dog,
>         cat
>     },
>     Sex = {
>         male,
>         female
>     },
>     BreedGroup = {
>         toy,
>         small,
>         medium,
>         large
>     },
>     Age = IntBands(0, 2, 4, 6, 8..),
>     Money = Num {precision: 0.01}
> }
>
> Constants = {
>     claims_fee [cite: countrywide:p11] = 3.25,
>     enroll_age_limit [cite: countrywide:p2] = 14
> }
>
> Tables = {
>     BaseRate [cite: countrywide:p4] :
>         table dims (pet: PetType) -> {
>             rate: Rate
>         }
>         path: "tables/BaseRate.csv",
>     BreedFactor [cite: countrywide:p6] :
>         table dims (group: BreedGroup) -> {
>             factor: Factor
>         }
>         path: "tables/BreedFactor.csv",
>     SexFactor [cite: countrywide:p7] :
>         table dims (sex: Sex) -> {
>             factor: Factor
>         }
>         path: "tables/SexFactor.csv",
>     AgeFactor [cite: countrywide:p8] :
>         table dims (age: Age) -> {
>             anniversary: Factor,
>             inception: Factor
>         }
>         path: "tables/AgeFactor.csv"
> }
>
> Records = {
>     Pet = {
>         inputs {
>             pet_type: PetType,
>             breed_group: BreedGroup,
>             sex: Sex,
>             age: Num {precision: int} where self in [0, 20]
>         },
>         step factors {
>             base_rate: Rate = lookup!(BaseRate, self.pet_type).rate,
>             breed_factor: Factor = lookup!(BreedFactor, self.breed_group).factor,
>             sex_factor: Factor = lookup!(SexFactor, self.sex).factor,
>             age_factor: Factor = lookup!(AgeFactor, self.age).anniversary,
>             inception_factor: Factor = lookup!(AgeFactor, self.age).inception
>         },
>         step premium {
>             monthly: Premium [cite: countrywide:p12] =
>                 round(
>                     (self.base_rate * self.breed_factor * self.sex_factor * self.age_factor + claims_fee) * self.inception_factor,
>                     2,
>                     half_up
>                 ),
>             annual: Premium [cite: countrywide:p12] = round(12 * self.monthly, 2, half_up)
>         }
>     } where self.age <= enroll_age_limit [code: "ENROLL_AGE", message: "A pet enrolls up to age 14.", cite: countrywide:p2]
> }
>
> RatingOutcomes = {
>     monthly_premium: Pet.monthly,
>     annual_premium: Pet.annual
> }
> ```
>
> ```csv pet-states/tables/BaseRate.csv theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
> pet,rate
> dog,38.50
> cat,21.10
> ```
>
> ```csv pet-states/tables/BreedFactor.csv theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
> group,factor
> toy,0.85
> small,1.00
> medium,1.18
> large,1.40
> ```
>
> ```csv pet-states/tables/SexFactor.csv theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
> sex,factor
> male,1.03
> female,1.00
> ```
>
> ```csv pet-states/tables/AgeFactor.csv theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
> age,anniversary,inception
> 0,0.80,1.00
> 2,1.00,1.00
> 4,1.25,1.00
> 6,1.60,1.10
> 8,2.10,1.25
> ```

The monthly premium is a chain of factors, plus a claims fee, times an inception factor:

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
monthly: Premium [cite: countrywide:p12] =
    round(
        (self.base_rate * self.breed_factor * self.sex_factor * self.age_factor + claims_fee) * self.inception_factor,
        2,
        half_up
    ),
```

Check the countrywide rater:

```sh theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
rslc check pet-states/base.rsl
```

```text theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
PASS pet-states/base.rsl (strict)
cost monthly_premium: 11 (each list of size 1: 11, 3: 11, 10: 11)
cost annual_premium: 12 (each list of size 1: 12, 3: 12, 10: 12)
```

## Name the base in a state file

Texas files the countrywide manual as it stands. Its memorandum reprints the claims fee, so the Texas rater cites the fee on that page.
Save `pet-states/tx.rsl`:

```rsl pet-states/tx.rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
# Texas: the countrywide manual. The Texas memorandum reprints the claims
# fee on its first page, so Texas cites it there.

spec {
    rsl: "0.4.2",
    carrier: "Example Mutual",
    state: TX,
    product: "Pet Accident and Illness",
    version: "1.0.0",
    effective_date: 2026-05-01
}

extends "base.rsl"

Sources = {
    tx_filing: Source = {
        artifact: artifact("00000000-0000-4000-8000-000000000403"),
        kind: pdf
    }
}

replace Constants = {
    claims_fee [cite: tx_filing:p1] = 3.25
}
```

* `rsl: "0.4.2"` is the RSL version that reads state files. The base keeps its own version.
* The `spec` block of the state file is the `spec` of the Texas rater.
* `extends "base.rsl"` names the base: a file in the folder of the state file.
* `Sources` declares the Texas filing. A plain section declares names of the state's own.
* `replace Constants` gives the claims fee the base's value and the Texas citation.

Check the state file:

```sh theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
rslc check pet-states/tx.rsl
```

```text theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
PASS pet-states/tx.rsl (strict)
cost monthly_premium: 11 (each list of size 1: 11, 3: 11, 10: 11)
cost annual_premium: 12 (each list of size 1: 12, 3: 12, 10: 12)
```

The check compiles the base, applies the state file to it, and checks the result as one rater.

## Replace what the state's pages change

The California pages file four tables and the claims fee, and add a breed group.
Save `pet-states/ca.rsl` and the California tables:

> [accordion] Complete example: pet-states/ca.rsl
>
> ```rsl pet-states/ca.rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
> # California: the countrywide manual with the California exception pages.
>
> spec {
>     rsl: "0.4.2",
>     carrier: "Example Mutual",
>     state: CA,
>     product: "Pet Accident and Illness",
>     version: "1.0.0",
>     effective_date: 2026-05-01
> }
>
> extends "base.rsl"
>
> Sources = {
>     ca_pages: Source = {
>         artifact: artifact("00000000-0000-4000-8000-000000000402"),
>         kind: pdf
>     }
> }
>
> Constants = {
>     senior_fee [cite: ca_pages:p4] = 2.50,
>     senior_age [cite: ca_pages:p4] = 10,
>     ca_enroll_age_limit [cite: ca_pages:p6] = 13
> }
>
> replace Types = {
>     BreedGroup = {
>         toy,
>         small,
>         medium,
>         large,
>         giant
>     }
> }
>
> replace Tables = {
>     BaseRate [cite: ca_pages:p1] :
>         table dims (pet: PetType) -> {
>             rate: Rate
>         }
>         path: "tables/ca/BaseRate.csv",
>     BreedFactor [cite: ca_pages:p2] :
>         table dims (group: BreedGroup) -> {
>             factor: Factor
>         }
>         path: "tables/ca/BreedFactor.csv",
>     SexFactor [cite: ca_pages:p3] :
>         table dims (sex: Sex) -> {
>             factor: Factor
>         }
>         path: "tables/ca/SexFactor.csv",
>     AgeFactor [cite: ca_pages:p4] :
>         table dims (age: Age) -> {
>             anniversary: Factor,
>             inception: Factor
>         }
>         path: "tables/ca/AgeFactor.csv"
> }
>
> replace Constants = {
>     claims_fee [cite: ca_pages:p5] = 3.60
> }
>
> amend Records = {
>     Pet = {
>         inputs {
>             microchipped: Bool
>         },
>         step senior {
>             senior_charge: Premium [cite: ca_pages:p4] = 0 exception when self.age >= senior_age then senior_fee
>         }
>     } where self.age <= ca_enroll_age_limit [code: "ENROLL_AGE", message: "In California a pet enrolls up to age 13.", cite: ca_pages:p6]
>         where self.microchipped [code: "CA_MICROCHIP", message: "California enrolls a microchipped pet.", cite: ca_pages:p6]
> }
>
> amend chain Pet.monthly {
>     senior: + self.senior_charge before inception_factor [cite: ca_pages:p4]
> }
>
> drop check "ENROLL_AGE" [cite: ca_pages:p6]
> ```
>
> ```csv pet-states/tables/ca/BaseRate.csv theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
> pet,rate
> dog,44.20
> cat,23.90
> ```
>
> ```csv pet-states/tables/ca/BreedFactor.csv theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
> group,factor
> toy,0.88
> small,1.00
> medium,1.21
> large,1.45
> giant,1.70
> ```
>
> ```csv pet-states/tables/ca/SexFactor.csv theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
> sex,factor
> male,1.02
> female,1.00
> ```
>
> ```csv pet-states/tables/ca/AgeFactor.csv theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
> age,anniversary,inception
> 0,0.78,1.00
> 2,1.00,1.00
> 4,1.22,1.00
> 6,1.55,1.10
> 8,2.00,1.25
> ```

Each `replace` names a declaration of the base and states the state's version of it.

| Form | Use it when the state's pages |
| - | - |
| `replace Tables = { … }` | Change a table, one row or many |
| `replace Constants = { … }` | Change a constant, or cite it on a state page |
| `replace Types = { … }` | Add a member to an enumeration, or file other bands |

### Replace a type and the tables it keys

California adds the breed group `giant`.
A replaced enumeration holds every member of the base's enumeration:

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
replace Types = {
    BreedGroup = {
        toy,
        small,
        medium,
        large,
        giant
    }
}
```

Each member of the base keeps its id, so every read of the base reads the same member. The new member `giant` takes the next id.

`BreedFactor` is keyed by `BreedGroup`, so California files it again with a row for `giant`.
A table that California declares in its own `Tables` section is keyed by California's `BreedGroup` already, so it stands as written.
A replaced table keeps the base's keys in the same order, and each column of the base under its name and type:

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
BreedFactor [cite: ca_pages:p2] :
    table dims (group: BreedGroup) -> {
        factor: Factor
    }
    path: "tables/ca/BreedFactor.csv",
```

The CSV file of a replaced table holds a row for each key of the base's rows.

### Change one row of a table

California changes the factor of male pets, and keeps the factor of female pets.
A table's rows are the rows of one file. A state that changes one row declares the whole table in `replace Tables` and names its own CSV:

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
SexFactor [cite: ca_pages:p3] :
    table dims (sex: Sex) -> {
        factor: Factor
    }
    path: "tables/ca/SexFactor.csv",
```

The California file `tables/ca/SexFactor.csv` holds both rows: `male` at 1.02, and `female` at the countrywide 1.00.

Each key compares by its declared type. A number key, such as the age band `2`, compares by value, so `2` and `2.0` are one key.

California files its own anniversary factors and keeps the countrywide inception factors. Its file `tables/ca/AgeFactor.csv` holds both columns.

### Replace a constant

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
replace Constants = {
    claims_fee [cite: ca_pages:p5] = 3.60
}
```

The new value has the type of the base's value.

## Add to a record and its chain

`amend Records` adds inputs, calculations and rules to a record of the base.
California asks whether the pet carries a microchip, and charges a fee for a senior pet:

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
amend Records = {
    Pet = {
        inputs {
            microchipped: Bool
        },
        step senior {
            senior_charge: Premium [cite: ca_pages:p4] = 0 exception when self.age >= senior_age then senior_fee
        }
    } where self.age <= ca_enroll_age_limit [code: "ENROLL_AGE", message: "In California a pet enrolls up to age 13.", cite: ca_pages:p6]
        where self.microchipped [code: "CA_MICROCHIP", message: "California enrolls a microchipped pet.", cite: ca_pages:p6]
}
```

Each added field has a name of its own. Each value of the base keeps its definition.

The senior charge joins the monthly premium before the inception factor.
`amend chain` adds a named step to the arithmetic of a calculation:

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
amend chain Pet.monthly {
    senior: + self.senior_charge before inception_factor [cite: ca_pages:p4]
}
```

* The chain of `Pet.monthly` starts from `base_rate`. Its steps read `breed_factor`, `sex_factor`, `age_factor`, `claims_fee` and `inception_factor`, in that order.
* A step is named by the value it reads. `before inception_factor` puts the new step between the claims fee and the inception factor.
* The base's `round` holds the whole chain, so it rounds the new total.
* The new step is the calculation `Pet.senior`. California's monthly premium is `round((base_rate × breed_factor × sex_factor × age_factor + claims_fee + senior_charge) × inception_factor, 2, half_up)`.

## Drop a base rule

The countrywide manual enrolls a pet up to age 14. California enrolls a pet up to age 13, under the same code:

```rsl theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
drop check "ENROLL_AGE" [cite: ca_pages:p6]
```

`drop check` removes each base rule with the code. A rule of the state's own `amend Records` keeps the code, so California refuses age 14 with its own message.

## Check and rate each state

```sh theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
rslc check pet-states/ca.rsl
```

```text theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
PASS pet-states/ca.rsl (strict)
cost monthly_premium: 13 (each list of size 1: 13, 3: 13, 10: 13)
cost annual_premium: 14 (each list of size 1: 14, 3: 14, 10: 14)
```

`rslc show` prints the merged program of a state file, with the file that supplies each declaration:

```sh theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
rslc show pet-states/ca.rsl
```

```text theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
# base.rsl <- ca.rsl
...
type         BreedGroup {csv_backed: false, members: [{name: toy, value: toy}, {name: small, value: small}, {name: medium, value: medium}, {name: large, value: large}, {name: giant, value: giant}], parent: null, subtracted: []}  # ca.rsl
...
constant     claims_fee = 3.6  {body: {kind: NumLit(value(3.6)), ty: Num}, citations: [{region: {kind: pdf_page, page: 5}, source: ca_pages}], ty: Num}  # ca.rsl
constant     enroll_age_limit = 14  {body: {kind: NumLit(value(14)), ty: Num}, citations: [{region: {kind: pdf_page, page: 2}, source: countrywide}], ty: Num}  # base.rsl
...
table        SexFactor {citations: [{region: {kind: pdf_page, page: 3}, source: ca_pages}], covers: {base: "base.rsl", file: "ca.rsl", keys: [sex], path: "tables/SexFactor.csv", table: SexFactor}, inputs: [{csv_header: sex, name: sex, ty: Enum(Sex)}], outputs: [{csv_header: factor, name: factor, ty: Factor}], path: "tables/ca/SexFactor.csv"}  # ca.rsl
...
drop         drop check "ENROLL_AGE"  # ca.rsl
```

The first line names the stack of files, lowest first, and the second line the identity of the merged program.

`rslc diff` prints the difference between two states. Texas adds its own source and cites the claims fee at the countrywide value:

```sh theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
rslc diff pet-states/tx.rsl pet-states/base.rsl
```

```text theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
~ source tx_filing
    tx.rsl: tx_filing spec{artifact: "00000000-0000-4000-8000-000000000403", kind: pdf}  # tx.rsl
    base.rsl: none
= constant claims_fee: same value (tx.rsl and base.rsl)
```

Build a rater from each file, and rate a male dog of a medium breed, aged 4:

```python theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
from relativities import Rater

raters = {name: Rater.build(f"pet-states/{name}.rsl") for name in ("base", "tx", "ca")}
dog = {"pet_type": "dog", "breed_group": "medium", "sex": "male", "age": 4}
california = {**dog, "microchipped": True}
for name, rater in raters.items():
    request = california if name == "ca" else dog
    print(name, rater.rate(request).to_pandas()["monthly_premium"].item())
# base 61.74
# tx 61.74
# ca 70.15
```

Texas rates as the countrywide manual: \$61.74 a month. California asks the added input `microchipped`, and its own tables give \$70.15.

A California dog aged 12 pays the senior charge before the inception factor:

```python theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
print(raters["ca"].rate({**california, "age": 12}).to_pandas()["monthly_premium"].item())
# 144
```

The premium is `round((44.20 × 1.21 × 1.02 × 2.00 + 3.60 + 2.50) × 1.25, 2, half_up) = 144.00`.

California refuses a pet aged 14 with its own message. The countrywide rater accepts 14 and refuses 15:

```python theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
for name, request in (("ca", {**california, "age": 14}), ("base", {**dog, "age": 14}), ("base", {**dog, "age": 15})):
    result = raters[name].rate(request).to_pandas()
    print(name, request["age"], result["status"].item(), result["reason"].item())
# ca 14 refused In California a pet enrolls up to age 13.
# base 14 succeeded None
# base 15 refused A pet enrolls up to age 14.
```

Keep each state file in the folder of its base. `Rater.build` compiles a state file as the bundle's `rater.rsl`, so name the base `base.rsl`, or any name other than `rater.rsl`.

## Export a state

`rslc export` packages the rater that a state file gives:

```sh theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
rslc export pet-states/ca.rsl --format bundle --out ca.zip
```

```text theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
WROTE bundle: ca.zip
```

The bundle holds the base's source, the state file, the tables the California rater reads, and the countrywide tables that check California's:

```python theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
from zipfile import ZipFile

print(*ZipFile("ca.zip").namelist(), sep="\n")
# base.rsl
# ca.rsl
# program-manifest.json
# program/input-schema.json
# program/program.py
# rater-manifest.json
# runtime/rslc_wasm.wasm
# tables/AgeFactor.csv
# tables/BaseRate.csv
# tables/BreedFactor.csv
# tables/SexFactor.csv
# tables/ca/AgeFactor.csv
# tables/ca/BaseRate.csv
# tables/ca/BreedFactor.csv
# tables/ca/SexFactor.csv
```

California replaces all four countrywide tables, so the rater reads each table from one California file. The bundle keeps each countrywide file, so a California file is checked for a row for each countrywide key wherever the bundle opens. The bundle's manifest lists each such base file in `source_files` with the kind `enum_csv`: it is data that a check reads, and the rater rates only on the California files.
`rslc check`, `rslc export` and the catalog all read the same California rater.

## Related

* [Language reference: state files](https://docs.effectiveai.app/rsl/reference/language.md#state-files) states every form and its rules.
* [Check messages: state files](https://docs.effectiveai.app/rsl/reference/check-messages/states.md) explains each message of a state file.
* [Split a rater into files](https://docs.effectiveai.app/rsl/how-to/split-a-rater-into-files.md) imports types and tables from a second file.
* [Versions](https://docs.effectiveai.app/rsl/explanation/versions.md) explains how a patch such as 0.4.2 relates to its line.


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