RULESCRIPT

Rules you can read.
One shared language.

RuleScript is an open language for validating and transforming data. Write your rules in .rules files.

The open RuleScript specification

The specification defines how to write and execute RuleScript rules. Anyone can implement it, and it guides the RuleGenius engine.

The same .rules file can combine transformations, checks and removal of identifying fields. The specification repository contains the catalogue and examples used on this page.

Browse the RuleScript repository ↗

Test your engine with starter conformance cases ↗

A small vocabulary. A predictable structure.

Give each rule a name.

Use one instruction per line inside a named rule block, indented with two spaces. No semicolons. Each check must pass; a final message explains a failure.

price.rules
rule "Valid price":
  check price is required
  check price is a number
  check price is between 0 and 10000
  message "Enter a numeric price from 0 to 10000"

Fields are references. Text is quoted.

price references a field; "price" is literal text. Use backticks for an exact header with spaces, Unicode or a reserved word, such as `Unit Price` or `check`. Double an embedded backtick. Expressions such as price * quantity are written directly.

columns.rules
rule "Read exact column headers":
  convert `Unit Price` to number
  convert quantity to integer
  set total to `Unit Price` * quantity
  set `Customer Note` to "Reviewed"

Put the condition first.

An optional when is the first instruction in the block. If its condition is false, that rule is skipped for the record. The same condition vocabulary works in check and keep rows where.

discount.rules
rule "Discount on larger orders":
  when price is greater than 100
  check discount is a number
  check discount is at least 0
  message "Discount must be a nonnegative number"

Make order and missing values explicit.

Rules and instructions run in written order on a working copy. CSV cells start as strings: convert them explicitly before numeric checks. Checks never silently convert or repair data.

Missing, null and empty text are distinct. Use is missing, is null or is required. Between includes both limits. A failed record prevents data output for the whole execution; filtering a row does not erase a previous failure.

supplier.rules
rule "Prepare supplier data":
  rename `Unit Price` to price
  convert price to number
  convert quantity to integer
  set total to price * quantity

rule "Valid price":
  check price is required
  check price is a number
  check price is between 0 and 10000
  message "Enter a numeric price from 0 to 10000"

rule "Supported country":
  check country is in ["US", "CA", "MX"]
  message "Country must be US, CA or MX"

22 entries shown

Transformations

Rename a field

Change a field name without changing its value. Backticks reference an exact CSV header containing spaces.

transform.rules
rule "Rename a column":
  rename `Unit Price` to price

Parameters: source field, new field

Split a field

Split a string using a literal separator. The number of parts must match the destination fields.

transform.rules
rule "Split a name":
  split full_name into first_name, last_name by " "

Parameters: source field, destination fields, separator

Merge fields

Join string fields in the written order using an explicit separator.

transform.rules
rule "Build a full name":
  merge first_name, last_name into full_name with " "

Parameters: source fields, destination field, separator

Map values

Replace a value using a map with quoted text keys. An unmapped value fails the record instead of silently passing through.

transform.rules
rule "Expand country codes":
  map country_code using {"US": "United States", "CA": "Canada", "MX": "Mexico"}

Parameters: field, mapping

Convert a type

Convert a field explicitly. CSV cells start as strings; checks never convert them implicitly. Invalid conversions fail the record.

transform.rules
rule "Read a quantity":
  convert quantity to integer

Parameters: field, number / integer / string / boolean / date

Set or calculate a field

Assign a literal, copy a field or evaluate an expression. Expressions are not quoted.

transform.rules
rule "Calculate a total":
  set total to price * quantity

Parameters: destination field, expression

Normalize text

Use set with a text function. The same assignment form works for lowercase, uppercase, titlecase and trim.

transform.rules
rule "Normalize a name":
  set name to lowercase(name)

Parameters: field, text function

Replace a value

Replace an exact typed value in a field. Replacing null does not replace an absent field or an empty string.

transform.rules
rule "Replace a null status":
  replace null with "N/A" in status

Parameters: old value, replacement, field

Round a number

Use round inside an assignment. Decimal ties round away from zero, so results do not depend on a runtime default.

transform.rules
rule "Round a price":
  set price to round(price, 2)

Parameters: number expression, decimal places (0–15)

Mask a value

Replace a field value with the supplied constant. Masking changes its display but does not establish dataset anonymity.

transform.rules
rule "Mask email":
  mask email with "****@domain.com"

Parameters: field, constant mask

Remove identifying fields

Anonymize explicitly named fields by removing them from the working data and output. This does not detect all PII or assess re-identification risk.

transform.rules
rule "Remove direct identifiers":
  anonymize email, phone, `Full Name`

Parameters: explicit fields to remove

Drop fields

Remove fields that are no longer needed. Use anonymize to express the intent to remove identifying fields.

transform.rules
rule "Drop a temporary field":
  drop temp_field

Parameters: fields

Fill missing values

Fill absent or null values with a literal or aggregate. Empty strings stay distinct. Mean and median use a snapshot of retained rows at the start of the rule.

transform.rules
rule "Fill an absent age":
  fill age with mean(age)

Parameters: field, value / mean(field) / median(field)

Reorder columns

List every retained field exactly once to set CSV output order. For JSON this only controls serialization order.

transform.rules
rule "Order output columns":
  reorder columns id, name, email

Parameters: all retained fields, in order

Keep matching rows

Keep rows for which the condition is true. Other rows are counted as filtered, not as failed checks. A prior failure cannot be erased by a later filter.

transform.rules
rule "Keep adult records":
  keep rows where age is at least 18

Parameters: condition

Validation groups

Required values

Reject absent fields, null, empty or whitespace-only strings, and empty collections. Zero and false are present values.

check.rules
rule "A name is required":
  check name is required
  message "Name is required"

Parameters: field

Data types

Check a type without converting it. Use a number, an integer, a string, a boolean or a date. Dates are valid ISO YYYY-MM-DD strings.

check.rules
rule "Age is numeric":
  check age is a number
  message "Age must be numeric"

Parameters: field, expected type

Ranges

Check an inclusive numeric range: both the lower and upper bounds are allowed.

check.rules
rule "A price is in range":
  check price is between 0 and 10000
  message "Price must be between 0 and 10000"

Parameters: field, inclusive minimum and maximum

Membership

Check exact, case-sensitive typed membership. Use is not in to exclude a list.

check.rules
rule "Country is supported":
  check country is in ["US", "CA", "MX"]
  message "Country must be US, CA or MX"

Parameters: field, list of values

Minimum values

Use is greater than for an exclusive threshold and is at least for an inclusive threshold.

check.rules
rule "Discount is positive":
  check discount is greater than 0
  check price is at least 0

Parameters: numeric field, threshold

Maximum values

Use is less than for an exclusive threshold and is at most for an inclusive threshold.

check.rules
rule "Discount is within its limit":
  check age is less than 18
  check discount is at most 50

Parameters: numeric field, threshold

Equality and exclusion

Use is or is not for equality, and is not in to exclude values. Fields, strings and numbers remain distinct.

check.rules
rule "Status is active":
  check status is "Active"
  check status is not in ["Inactive", "Suspended"]

Parameters: field, value or excluded list

Mask a value. Remove identifying fields.

Mask replaces a field with a fixed string. Anonymize removes the explicitly named fields from working records and output, for example email, phone and a full name. Neither operation automatically finds all PII.

privacy.rules
rule "Remove identifying fields":
  anonymize email, phone, `Full Name`

Run removal after rules that need those fields. Inputs stay unchanged, and reports must not echo raw record values. Other attributes can still identify people in combination; removing direct identifiers is one step in a broader de-identification process.

Read the exact mask/anonymize semantics · NIST SP 800-188

One file. One execution.

The file determines what happens. CLI and API share a source-only preview mode and a separate execution mode that applies every instruction in order. Both planned interfaces follow the RuleScript specification.

Explain the plan before running it.

Use --preview with only the .rules file. The plan explains every rule in order: its condition, steps, fields read or changed, fields removed and failure message. It does not read a dataset, evaluate values or produce transformed data.

CLI preview
rulegenius supplier.rules --preview

Illustrative plan for the downloadable supplier rules; the runtime planner is not released yet.

Example plan
Preview only — no data inspected or rules executed

1. Prepare supplier data
   Rename `Unit Price` to price
   Convert price to number and quantity to integer
   Set total to price * quantity

2. Valid price
   Require price, check its number type and inclusive range 0–10000
   On check failure: "Enter a numeric price from 0 to 10000"

3. Supported country
   Check that country is US, CA or MX
   On check failure: "Country must be US, CA or MX"

Actual field availability, values and row outcomes remain unknown.

The same endpoint accepts mode=preview with a rules file and no data part. A valid plan has status ready, executed false, data_inspected false and output null. It does not predict check outcomes, row counts or successful anonymization.

API preview
POST /v1/executions
Content-Type: multipart/form-data

rules: @supplier.rules
mode:  preview

Add --report plan.json to save the structured plan. Preview rejects a data file or --output. Execution is a separate explicit command/request. The plan identifies the exact source file; regenerate it if your rules change.

Read the preview contract and JSON examples ↗

CLI

CLI
rulegenius supplier.rules input.csv --output output.csv --report report.json

To execute after reviewing a plan, provide the rules file, data file and --output. Output is written atomically only when every retained record passes and no earlier failure remains. The optional JSON report describes the run.

API

HTTP
POST /v1/executions
Content-Type: multipart/form-data

rules: @supplier.rules
data:  @input.csv

For execution, send multipart parts rules and data; mode defaults to execute. CSV and JSON arrays of records use the same endpoint. HTTP 200 means the execution completed; inspect status for passed or failed. A failed execution returns a report with output set to null.

Read the CLI and API contract ↗

Try two checks in your browser.

This browser-only demonstration checks a numeric price from 0 to 10000 and a country code in US, CA or MX. It is a small JavaScript example, not the RuleScript parser or execution engine. Your input stays in this page.

0 ≤ price ≤ 10000 · country ∈ {US, CA, MX}

Run the checks to see a result.