Skip to main content
These examples require rslc 0.8.0, included with the matching Relativities release. Use RSL 0.4.2 when your plan needs verification or underwriting. Use the RSL 0.5 authoring preview to try module and function syntax for supported raters. The first two examples return the entered amount as written premium, up to $100. Each example uses a separate folder for checking and packaging.

Write the rating rule

Save this file as legacy/rater.rsl. The rsl field in spec selects the edition. RatingOutcomes names the result.
legacy/rater.rsl
Save this file as preview/rater.rsl. The first line selects RSL 0.5. The module names the entry function, and show names the result. The sample uses the same cent grid and input range as the first file.
preview/rater.rsl
In RSL 0.5, put a business refusal in the entry function or on the input record. A helper called from a calculation cannot declare a check. If a check applies only when the entry calls a helper, include that condition in the entry check. Inputs that skip the call can then proceed.

Check and export both files

Check the profile in each report. RSL 0.4 uses verify. RSL 0.5 uses preview, which checks the supported authoring forms and reports errors in the source. If you change Money to an undefined type in the preview file, the check fails with E-UNRESOLVED and points at the type name. Fix the error before exporting.
Each command writes a bundle with its own identity. Keep the ZIP for the edition you intend to run and the corresponding source files for your next edit. Both files accept rslc fmt FILE for canonical formatting. A required field can hold another record. Declare coverage: Coverage in Policy, declare the scalar rating fields in Coverage, and read them through that field, for example policy.coverage.amount. The exported input schema describes a nested JSON object. If the amount is out of range, the refusal names Policy.coverage.amount. Declare coverage: Coverage? if the request can omit the object. The schema allows either the object or null. Omitting the field or sending null selects the none arm. When a request supplies an object, its fields follow the Coverage declaration, and the some arm can read them.
optional-record/rater.rsl

Calculate a value on an optional child

A for block over an optional child declares a calculation on the child. Read the calculation in the some arm of a match. The none arm handles a missing or null child. Save the example as optional-child-calculation/rater.rsl.
optional-child-calculation/rater.rsl

Accept several records in one field

A plain List(Exposure) keeps the same input shape in both editions. Save this RSL 0.4.2 example as legacy-list/rater.rsl. The record and its inputs are declared under Records.
legacy-list/rater.rsl
Save the RSL 0.5 version as preview-list/rater.rsl. The item type and the containing record are declared at module scope.
preview-list/rater.rsl
Send {"Policy":{"amount":10,"exposures":[{"amount":5.25},{"amount":12}]}} to supply two items. An empty array, a missing exposures field, and "exposures": null all supply an empty list. Each item is validated independently. For example, an amount over 100 in the second item is refused at Policy.exposures[1].amount.

Require a bounded list

Put count in [1, 3] inside the list declaration to require at least one item and admit up to three. Save this example as bounded-list/rater.rsl and use an RSL 0.5 preview build that supports list counts.
bounded-list/rater.rsl
A missing or null exposures field supplies zero items, as does an empty array. Each fails the minimum with INPUT-LEN at Policy.exposures. Four items fail the maximum at the same path. The published input schema marks exposures required and lists the limits as minItems and maxItems.

Rate a keyed list and break a tie

Use key number to require a unique number for each exposure in the list. Calculate each exposure’s charge in a for block, add the rounded charges with sum, and use argmax to select the exposure with the highest charge. The tie key clause selects the lowest number when charges are equal. Save this example as keyed-list/rater.rsl and use an RSL 0.5 preview build that supports keyed records and selectors.
keyed-list/rater.rsl
Send this JSON input to the rater.
The rater rounds each charge to 0.51 and returns a premium of 1.02. Both charges tie, so lead_number is 10 even though that exposure comes second. When the list is empty, sum returns zero and argmax returns none. The example returns lead_number as 0 in that case. Reusing number 20 for the second item returns INPUT-KEY at Policy.exposures[1].number.

Select a matching record from a keyed list

Use find(item.eligible for item in policy.items) to get the first eligible item by ascending declared key. A match returns some item. A list with no match returns none. The query stops at the first match, so later rows do not have to calculate the predicate. Use record Item key number when the input uses the submitted item number as its key.

Group arithmetic with a fallback

RSL 0.5 requires parentheses when otherwise and arithmetic meet at the same level. For amount otherwise base + fee, rslc reports E-FALLBACK-GROUPING and suggests both ways to group it. With amount otherwise (base + fee), the fee applies only when amount is absent. With (amount otherwise base) + fee, the fee applies to either amount. Save this example as optional/rater.rsl.
optional/rater.rsl
Check the example before exporting it.
An omitted or null amount takes the fallback of 7. An explicit zero stays zero. The nonoptional fee defaults to 1 when omitted or null. An explicit zero overrides the default.

Read a list of enum values

A field declared as choices: List(Choice) takes a JSON array such as ["alpha", "beta"] when Choice declares those enum members. An empty array is valid. The field is required, and each invalid item receives its own input path, such as Policy.choices[1]. A comprehension can read a table cell for each member in the submitted order, for example sum(Charges[choice].charge for choice in policy.choices). Repeated members contribute once per appearance. Use a count in [1, 3] check on the field to require one to three entries. The input schema exposes the same minimum and maximum, and the runtime reports a length violation at the field path.

Narrow an enum input

A named subset such as type Polygon = Piece in {.rectangle, .triangle} retains the member wire values from Piece. Use piece: Polygon to require an input from that subset. An unknown wire value receives INPUT-ENUM. A wire value that belongs to Piece but falls outside Polygon receives INPUT-REFINEMENT at the input’s path.

Read a tagged input

A required tagged input takes a JSON object with a tag and the fields for that arm. For type Origin = { measured "Measured" { amount: Num }, estimated "Estimated" }, send {"tag":"Measured","amount":12} or {"tag":"Estimated"}. Match on the source name, as in .measured m => m.amount. The request uses the declared wire spelling, such as "Measured". Use type Status = tagged { absent "Absent", recorded "Recorded" } when every arm is empty. Send {"tag":"Recorded"} and match with .recorded. An ordinary enum input takes the string "Recorded". A scalar payload field can be optional or require a filed table key. Admission checks the selected arm and reports an invalid value at its nested field path. The input schema lists the closed alternatives in oneOf.

Look up a text code

A Text input receives a JSON string. Use it for codes whose spelling matters. For example, "0012" and "12" can name different rows, and sending the number 12 gives an input type refusal.
text-keys/rater.rsl
To read these rows from a CSV, add from "classes.csv" to the table declaration, move the two filed rows to that file, and use class_code,factor,label as its header. Exact key lookup preserves the text in each cell. A Text field can receive strings outside the table, so a lookup using that field needs an otherwise row.

Require a filed table key

Write the table and key column, such as Classes.class_code, to admit only values that name a filed row. This corresponds to Key(Classes) in a legacy rater with one key column. The input keeps that column’s type and wire representation. A table’s otherwise row does not make a value a filed key.
filed-keys/rater.rsl
A string that fails the Code pattern is an input error. A well-formed string that has no row gets the authored refusal. Omit or refuse to use the standard INPUT-KEY-UNFILED response. Both editions reserve the wire value unfiled for a blank cell in a table output enum. Use another member value for a filed row. A Text output can contain the literal word unfiled. For a band lookup without a fallback, the compiler must prove that a computed key stays inside the filed bands. A bounded input can still yield an out-of-range key after subtraction. Check the bounds of the calculation, including the first and last cut and the grid that the filing specifies.

Keep child records in the result

Add layout nested to an RSL 0.5 rating entry when callers read child records. Use entry rate detail demand layout nested to combine nested results with demand-only detail. The public and detailed results include the declared input record and list hierarchy. A present child produces an object with its published fields and nested child structure. An omitted or null optional child produces null. A list keeps request order and produces [] when empty. The layout does not echo scalar inputs. Use the same show lines to publish calculation results. With detail demand, detailed results also include the calculations the rating evaluated. The input contract stays the same. Native and Worker readers need to support the layout before loading a bundle that uses it.

Publish calculations on an optional child

With layout nested, a for over an owned record field writes calculations on that record. When the field is optional, the block has one instance if the request supplies the child and no instance if the field is omitted or null. Publish the child’s result inside the block, as you do for list items.
nested-child/rater.rsl
A request with a coverage amount of 100 produces {"Policy":{"coverage":{"risk_charge":100}}} in the outputs. An omitted or null coverage produces {"Policy":{"coverage":null}}. The entry’s detail demand setting also keeps demanded calculations on the child.

Refer to a sibling record by key

A required Ref(Driver) field can identify an item in a sibling List(Driver) on the immediate owner. Declare a key on Driver, then send the key as the reference field’s value. A calculation can read through the reference with a path such as vehicle.primary_driver.amount. Admission rejects duplicate list keys and references that have no matching item.

Use enum-indexed maps

Declare a required input such as limit: Num[Coverage] @ 1 in [0, 100]. Send a JSON object with a value for every wire key in Coverage. The interval and grid apply to each cell. Read a cell with policy.limit[policy.coverage]. Define a calculated map with a declaration such as let charge[c: Coverage]: Num = policy.limit[c] * 2. Use show charge to publish the map as an object keyed by the enum’s wire values.

Choose the edition for your plan

The RSL 0.5 preview covers a subset of rating authoring with scalar and record inputs. Use RSL 0.4 for scenario evaluation with rslc eval, proof checks, underwriting and submission logs, or any rating form the preview refuses. Keep an existing rater in the edition it declares until you have compared the outcome and input contract of a rewritten version. See Versions for the language, compiler, and bundle versions. See Programs on Effective for working with a completed bundle.