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

# Use the rslc commands

> Check, format and package a rater with rslc, generate test requests from its rules, and rate requests from Python.

[Install Relativities and download the synthetic examples](/relativities/setup) before running this page.

`rslc` is the command-line tool for RSL raters. This page shows each command on the dwelling fire
rater from [Write your first rater](/relativities/rsl/tutorial/first-rater), with the output it prints.

```mermaid theme={null}
flowchart LR
  source["rater.rsl and tables"] --> check["rslc check"]
  source --> fmt["rslc fmt"]
  check --> export["rslc export"]
  export --> bundle["Bundle ZIP"]
  bundle --> python["rslc.PreparedRater in Python"]
  bundle --> relativities["Rater.load in Relativities"]
  source --> inputs["rslc inputs sample"]
```

| Command | Use it to |
| - | - |
| `rslc check` | prove the rater's promises before you package it |
| `rslc fmt` | lay out the source in the standard style |
| `rslc export` | package the rater as a bundle |
| `rslc inputs sample` | generate requests from the rater's own rules |
| `rslc inputs validate` | check one request against the rules |

Each command exits with status 0 when it succeeds and 1 when it fails, so a script or CI job
can stop on a failure.

## Check a rater

`rslc check` reads the rater and its tables, and proves every promise in
[What rslc checks and guarantees](/relativities/rsl/explanation/checks-and-guarantees):

```bash theme={null}
rslc check rater.rsl
```

```text theme={null}
PASS rater.rsl (strict)
cost premium: 12 + 2*|Policy.items| (each list of size 1: 14, 3: 18, 10: 32)
```

The second line is the cost line. It counts the steps of work for each outcome.

A failed check prints one line for each problem. The line gives the message code, the file, the
line and column, and the fix:

```text theme={null}
FAIL rater.rsl (strict)
error: E-PROVENANCE rater.rsl:31:5: table `BaseRate` has no citation
  = because: every filed number cites the filing region that states it; a number no filing states says why in `[reason: "…"]`
  = help: cite the region that prints it: `BaseRate [cite: manual:p12] : table dims (…)`
  = applicability: manual
cost premium: 12 + 2*|Policy.items| (each list of size 1: 14, 3: 18, 10: 32)
```

* `because` gives the reason for the rule.
* `help` shows a rewrite. Replace the example citation with the real one.
* `applicability: manual` means the author applies the fix by hand.

[Check messages](/relativities/rsl/reference/check-messages) lists each code with its fix.

For tools and scripts, put `--json` before the command name. The output is one JSON object with
the keys `ok`, `diagnostics`, `cost` and `summary`, among others:

```bash theme={null}
rslc --json check rater.rsl
```

## Format a rater

`rslc fmt` rewrites the source in the standard layout. `--check` reports the change and leaves the
file as it is:

```bash theme={null}
rslc fmt --check rater.rsl
```

```text theme={null}
FAIL rater.rsl needs formatting
--- rater.rsl
+++ rater.rsl
@@ -24,7 +24,7 @@
 }

 Constants = {
-  expense_fee [cite: manual:p9]   =   35
+    expense_fee [cite: manual:p9] = 35
 }

 Tables = {
```

To fix the layout, run the command alone:

```bash theme={null}
rslc fmt rater.rsl
```

```text theme={null}
FORMATTED rater.rsl
```

## Package a rater

`rslc export` packages the rater as a **bundle**: one ZIP file that holds the source, the tables and
a manifest.

```bash theme={null}
rslc export rater.rsl --format bundle --out dwelling.zip
```

```text theme={null}
WROTE bundle: dwelling.zip
```

| File in the bundle | Holds |
| - | - |
| `rater.rsl` | the source |
| `tables/*.csv` | the table rows |
| `rater-manifest.json` | the bundle's identity and its list of files |
| `rater.py` | a Python version of the rater |

* Run `rslc check` first, and package a rater only after it passes. `rslc export` stops on a calculation that can fail, and leaves the citation and outcome checks to `rslc check`.
* The command writes a new ZIP file, and stops when the file already exists.
* It also writes `rater-manifest.json` and `rater.py` beside the source. `--format python` writes only `rater.py`.

## Rate from Python

`rslc.PreparedRater` loads an unpacked bundle folder. `rate` takes one request as JSON text and
returns a JSON result. The sample download includes this bundle in
`relativities-examples/rsl/dwelling-fire`:

```python theme={null}
import json

import rslc

rater = rslc.PreparedRater("relativities-examples/rsl/dwelling-fire")
policy = {"Policy": {"dwelling": {"coverage_a": 250000, "protection_class": 5}, "items": [{"value": 1200}, {"value": 800}]}}
print(rater.rate(json.dumps(policy)))
# {"ok":true,"outputs":{"Policy":{"dwelling":{},"items":[{},{}],"premium":1028}}}
```

* A rated request returns `"ok": true` and the outcomes under `outputs`.
* A refused request returns `"ok": false` and a `refusal`. [Refusals](/relativities/rsl/reference/refusals) describes it.
* `detailed=True` adds every calculation to `outputs`.

`rate_describe` returns JSON Schemas for the request, the output and the detailed output. An
integration can build its forms and checks from them:

```python theme={null}
describe = json.loads(rater.rate_describe())
print(sorted(describe))
# ['detailedOutputSchema', 'inputSchema', 'outputSchema']
print(describe["inputSchema"]["properties"]["Policy"]["properties"]["dwelling"]["properties"]["protection_class"])
# {'maximum': 10.0, 'minimum': 1.0, 'type': 'integer'}
```

The schema describes the shape of a request. The rater's own check of each request decides a
refusal.

To rate a table of many policies with pandas, load the bundle ZIP with `Rater.load`. See
[Rate submissions with a rater](/relativities/how-to/rate-submissions-with-a-rater).

## Generate requests from the rules

`rslc inputs sample` builds requests that pass every rule. `--representation rate` prints them in
the request form that `rate` takes:

```bash theme={null}
rslc inputs sample rater.rsl --n 5 --representation rate --json-lines samples.jsonl
```

```text theme={null}
Generated 5 valid inputs from rater.rsl
{"Policy": {"dwelling": {"coverage_a": 1025000.0, "protection_class": 1.0}, "items": [{"value": 25000.0}]}}
{"Policy": {"dwelling": {"coverage_a": 50000.0, "protection_class": 1.0}, "items": [{"value": 25000.0}]}}
{"Policy": {"dwelling": {"coverage_a": 1025000.0, "protection_class": 1.0}, "items": [{"value": 0.01}]}}
{"Policy": {"dwelling": {"coverage_a": 2000000.0, "protection_class": 1.0}, "items": [{"value": 25000.0}]}}
{"Policy": {"dwelling": {"coverage_a": 1025000.0, "protection_class": 10.0}, "items": [{"value": 25000.0}]}}
```

* `--n` sets the number of requests, and `--seed` fixes the random choices.
* `--json-lines` also writes each request to a file, one JSON row per line, under the key `input`.
* `--invalid` builds requests that break one rule each, and records the expected refusal.

[Test a rater](/relativities/rsl/how-to/test-a-rater) rates these files.

## Check one request

`rslc inputs validate` checks one request against the rules. It reads the evaluator form, the default
form of `rslc inputs sample`:

```bash theme={null}
rslc inputs sample rater.rsl --n 1
```

```text theme={null}
Generated 1 valid inputs from rater.rsl
{"instances": [{"entity": "Policy", "name": "policy_1", "values": {}}, {"entity": "Dwelling", "name": "dwelling_2", "values": {"__parent": "policy_1", "coverage_a": 1025000.0, "protection_class": 1.0}}, {"entity": "Item", "name": "item_3", "values": {"__parent": "policy_1", "value": 25000.0}}]}
```

Save that object as `candidate.json`. Save a copy with `protection_class` set to 11 as
`bad-candidate.json`:

```bash theme={null}
rslc inputs validate rater.rsl candidate.json
rslc inputs validate rater.rsl bad-candidate.json
```

```text theme={null}
PASS input for rater.rsl
FAIL input for rater.rsl
{'field': 'protection_class', 'instance': 'dwelling_2', 'issue': 'out_of_range', 'rule': 'field', 'rule_id': {'entity': 'Dwelling', 'field': 'protection_class', 'kind': 'field_domain'}}
```

To check a request in the `rate` form, rate it with `PreparedRater`.


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