# Ruleset

### **Overview**

The **Ruleset Node** in UPTIQ Workbench serves as an abstraction that allows developers to **integrate Rulesets into workflows** seamlessly. It helps evaluate **specific records** against predefined **business rules**.

Rulesets are defined separately and can be used to enforce business logic, such as **eligibility checks, risk assessments, or compliance validation**. The **Ruleset Node enables developers to apply these rules dynamically to real-time data**, ensuring that decisions are made based on **runtime inputs**.

For detailed information on how Rulesets are created and managed, refer to the **Ruleset Section** in the developer guide.

### **Configurations**

| Field        | Description                                                                     |
| ------------ | ------------------------------------------------------------------------------- |
| **Ruleset**  | Select a predefined Ruleset or create a new one using the "Add Ruleset" button. |
| **Mappings** | Define how runtime data maps to the Ruleset’s **Facts** for rule evaluation.    |

#### **Mappings Explained**

Once a Ruleset is selected, developers must **map input data** to the **Facts** defined in the Ruleset. This mapping consists of:

1. **Target (Fact in Ruleset)**
   * This field is **auto-populated** based on the Facts defined in the selected Ruleset.
   * Example: If the Ruleset has Facts **LoanAmount** and **Age**, these will appear as Targets.
2. **Source (Value Assigned to the Fact at Runtime)**
   * This field defines **where the value for the Fact should come from**.
   * The value can be sourced from:\
     ✅ A **workflow variable** (e.g., data stored at the agent level).\
     ✅ The **output of a previous node** (e.g., fetched from a database).\
     ✅ A **static value** (if needed).

**Example Mapping Setup:**

| **Source (Runtime Value)**   | **Target (Ruleset Fact)** |
| ---------------------------- | ------------------------- |
| `$input.requestedLoanAmount` | `LoanAmount`              |
| `$input.borrowerAge`         | `Age`                     |

When executed, the workflow dynamically assigns runtime values to the **Ruleset’s Facts**, allowing the rules to be **evaluated against real data**.

### **Example Use-Case**

#### **1. Applying Knockout Rules for Borrowers**

**Scenario:**\
A loan origination workflow applies **knockout rules** to identify applications that should be declined **before entering the origination process**. A **Ruleset named "Borrower Knockout Rules"** has been defined with the following **Facts and Rules**:

* **Fact:** `LoanAmount` → Rule: **Must be greater than $100**
* **Fact:** `Age` → Rule: **Must be greater than 18**

At runtime, loan application details are **retrieved from a table** using a **Table Read Node** and passed to the **Ruleset Node**.

**Loan Application Data (Fetched at Runtime)**

```json
{
  "requestedLoanAmount": 150,
  "borrowerAge": 19
}
```

**Ruleset Node Configuration**

| Field                                     | Value                     |
| ----------------------------------------- | ------------------------- |
| **Ruleset**                               | Borrower Knockout Rules   |
| **Mappings**                              |                           |
| **Source =** `$input.requestedLoanAmount` | **Target =** `LoanAmount` |
| **Source =** `$input.borrowerAge`         | **Target =** `Age`        |

**Workflow Execution & Ruleset Evaluation**

During execution, the **Ruleset Node evaluates the conditions** based on runtime values:

* `LoanAmount = 150` → ✅ **Rule Passed (Approved)**
* `Age = 19` → ✅ **Rule Passed (Approved)**

**Ruleset Node Output Format**

```json
[
  {
    "event": "Check for Loan Amount",
    "params": {
      "loanAmount": "approved"
    }
  },
  {
    "event": "Check for Age",
    "params": {
      "age": "approved"
    }
  }
]
```

🔹 **What This Means:** The borrower meets the knockout rule conditions, so the application **should proceed to the next stage** in the workflow.&#x20;

### **Key Takeaways for Developers**

✅ **Automates Business Rule Enforcement** – The Ruleset Node **applies pre-defined logic dynamically** to evaluate records against **business rules in real-time**.

✅ **Seamless Workflow Integration** – Developers can map **runtime values** from previous nodes (such as Table Read or API responses) directly into Ruleset Facts, ensuring rules are evaluated against **live data**.

✅ **Enables Conditional Workflow Execution** – By checking **which rules pass or fail**, developers can design workflows that **automatically approve, reject, or trigger additional actions** based on rule evaluation.

✅ **Improves Decision-Making Efficiency** – Instead of **hardcoding** business logic into workflows, **rules are managed separately** in a Ruleset, making updates easier and reducing workflow complexity.

✅ **Flexible Data Mapping** – Mappings allow data to be sourced from **agent-level variables, previous node outputs, or static values**, giving developers full control over **runtime rule execution**.

By leveraging the **Ruleset Node**, developers can **implement complex business logic in a structured, reusable, and scalable manner**, ensuring that **workflows execute with rule-based intelligence**. 🚀
