> For the complete documentation index, see [llms.txt](https://docs.xyb.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.xyb.co/xyb-platform-1/xyb-ledger/integrate-with-xyb-ledger/set-up-transaction-workflows/managing-rules-and-attributes-in-ledger.md).

# Managing Rules & Attributes in Ledger

Attributes and rules play a crucial role in the operational phase by **governing, enhancing, and contextualizing** the actions performed, such as creating instructions, executing movements, and generating postings. Here's how they connect:

***

### Role of Attributes in Ledger

Attributes are metadata attached to ledger elements (accounts, wallets, instructions, movements) to provide context or enforce specific behaviors. They ensure that operations are tailored to meet system and business-specific requirements.

**How Attributes Connect to Ledger Operations:**

* **Enhancing Instructions**:
  * Attributes like `purpose`, `transaction_type`, or `customer_id` can be attached to instructions.
  * Example:

    ```json
    {
      "instruction_id": "12345",
      "attributes": {
        "transaction_type": "refund",
        "customer_id": "C001"
      }
    }
    ```
  * This ensures that the instruction carries relevant metadata for auditing or downstream processing.
* **Context for Movements**:
  * Movements inherit attributes from instructions or have their own (e.g., `allow_partial`, `priority`).
  * Example:

    ```json
    {
      "movement_id": "m001",
      "attributes": {
        "priority": "high",
        "allow_partial": true
      }
    }
    ```

    This can be used to prioritize specific movements during processing.
* **Categorizing Accounts and Wallets**:
  * Attributes help classify accounts and wallets to enforce rules during operations.
  * Example: An attribute `account_type=corporate` ensures only corporate funds are used for specific instructions.

**Why Attributes Are Important:**

* They allow **customization** of operations without changing core logic.
* They provide **granularity** for business-specific scenarios, like tagging high-value transactions.

***

### Rules in Ledger

Rules define the operational constraints and validations that ensure transactions comply with business policies, regulatory requirements, and system integrity.

**How Rules Connect to Operations:**

* **Instruction Validation**:
  * Rules can validate attributes on instructions or enforce specific actions.
  * Example: A rule ensures that refunds (`transaction_type=refund`) do not exceed the original transaction amount.
* **Movement Constraints**:
  * Rules determine whether a movement can proceed based on conditions like:
    * Sufficient funds in the debit wallet.
    * Matching currencies between debit and credit wallets.
    * Consolidated balance evaluations (e.g., `check_gcb_multi`).
  * Example Rule:

    ```json
    {
      "name": "check_gcb_multi",
      "parameters": {
        "datasheet": "/datasheet/exchange_rates",
        "tolerance": 5
      }
    }
    ```
* **Posting and Balance Restrictions**:
  * Rules can enforce restrictions on how postings affect wallet balances.
  * Example:
    * A rule disallows negative balances on customer wallets (`disallow_negative_customer_balance`).
* **Automation Triggers**:
  * Rules trigger specific automated actions based on operational conditions.
  * Example:
    * If an account balance falls below a threshold, a rule triggers a notification or a fund transfer.

**Why Rules Are Important:**

* **Validation**: They ensure that every operation complies with predefined constraints.
* **Control**: They prevent invalid operations, like unauthorized transfers or insufficient funds.
* **Automation**: They streamline complex workflows by enforcing predefined responses to specific conditions.

***

By working together, **attributes and rules** create a framework where operations are **dynamic, governed, and tailored** to the specific needs of the ledger's use cases.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.xyb.co/xyb-platform-1/xyb-ledger/integrate-with-xyb-ledger/set-up-transaction-workflows/managing-rules-and-attributes-in-ledger.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
