Rename a field
Change a field name without changing its value. Backticks reference an exact CSV header containing spaces.
rule "Rename a column":
rename `Unit Price` to priceParameters: source field, new field
RuleScript is an open language for validating and transforming data. Write your rules in .rules files.
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.
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.
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"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.
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"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.
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"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.
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
No matching rules. Try another term.
Change a field name without changing its value. Backticks reference an exact CSV header containing spaces.
rule "Rename a column":
rename `Unit Price` to priceParameters: source field, new field
Split a string using a literal separator. The number of parts must match the destination fields.
rule "Split a name":
split full_name into first_name, last_name by " "Parameters: source field, destination fields, separator
Join string fields in the written order using an explicit separator.
rule "Build a full name":
merge first_name, last_name into full_name with " "Parameters: source fields, destination field, separator
Replace a value using a map with quoted text keys. An unmapped value fails the record instead of silently passing through.
rule "Expand country codes":
map country_code using {"US": "United States", "CA": "Canada", "MX": "Mexico"}Parameters: field, mapping
Convert a field explicitly. CSV cells start as strings; checks never convert them implicitly. Invalid conversions fail the record.
rule "Read a quantity":
convert quantity to integerParameters: field, number / integer / string / boolean / date
Assign a literal, copy a field or evaluate an expression. Expressions are not quoted.
rule "Calculate a total":
set total to price * quantityParameters: destination field, expression
Use set with a text function. The same assignment form works for lowercase, uppercase, titlecase and trim.
rule "Normalize a name":
set name to lowercase(name)Parameters: field, text function
Replace an exact typed value in a field. Replacing null does not replace an absent field or an empty string.
rule "Replace a null status":
replace null with "N/A" in statusParameters: old value, replacement, field
Use round inside an assignment. Decimal ties round away from zero, so results do not depend on a runtime default.
rule "Round a price":
set price to round(price, 2)Parameters: number expression, decimal places (0–15)
Replace a field value with the supplied constant. Masking changes its display but does not establish dataset anonymity.
rule "Mask email":
mask email with "****@domain.com"Parameters: field, constant mask
Anonymize explicitly named fields by removing them from the working data and output. This does not detect all PII or assess re-identification risk.
rule "Remove direct identifiers":
anonymize email, phone, `Full Name`Parameters: explicit fields to remove
Remove fields that are no longer needed. Use anonymize to express the intent to remove identifying fields.
rule "Drop a temporary field":
drop temp_fieldParameters: fields
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.
rule "Fill an absent age":
fill age with mean(age)Parameters: field, value / mean(field) / median(field)
List every retained field exactly once to set CSV output order. For JSON this only controls serialization order.
rule "Order output columns":
reorder columns id, name, emailParameters: all retained fields, in order
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.
rule "Keep adult records":
keep rows where age is at least 18Parameters: condition
Reject absent fields, null, empty or whitespace-only strings, and empty collections. Zero and false are present values.
rule "A name is required":
check name is required
message "Name is required"Parameters: field
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.
rule "Age is numeric":
check age is a number
message "Age must be numeric"Parameters: field, expected type
Check an inclusive numeric range: both the lower and upper bounds are allowed.
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
Check exact, case-sensitive typed membership. Use is not in to exclude a list.
rule "Country is supported":
check country is in ["US", "CA", "MX"]
message "Country must be US, CA or MX"Parameters: field, list of values
Use is greater than for an exclusive threshold and is at least for an inclusive threshold.
rule "Discount is positive":
check discount is greater than 0
check price is at least 0Parameters: numeric field, threshold
Use is less than for an exclusive threshold and is at most for an inclusive threshold.
rule "Discount is within its limit":
check age is less than 18
check discount is at most 50Parameters: numeric field, threshold
Use is or is not for equality, and is not in to exclude values. Fields, strings and numbers remain distinct.
rule "Status is active":
check status is "Active"
check status is not in ["Inactive", "Suspended"]Parameters: field, value or excluded list
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.
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.
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.
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.
rulegenius supplier.rules --previewIllustrative plan for the downloadable supplier rules; the runtime planner is not released yet.
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.
POST /v1/executions
Content-Type: multipart/form-data
rules: @supplier.rules
mode: previewAdd --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 ↗
rulegenius supplier.rules input.csv --output output.csv --report report.jsonTo 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.
POST /v1/executions
Content-Type: multipart/form-data
rules: @supplier.rules
data: @input.csvFor 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 ↗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.