> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kaireonai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Natural Language Rule Building

> Create decisioning gates, contact policies, and behavioral metrics from natural language.

## Overview

KaireonAI lets you create decisioning gates, contact policies, and behavioral metrics by describing them in plain English using the built-in AI chat panel. Instead of manually configuring field names, operators, and values, open the AI assistant and type a sentence like "create a decisioning gate for customers over 25 who spent more than \$500 in the last 90 days" — the AI builds structured entity definitions and shows you a preview before creating them.

Open the AI chat panel with **Cmd+I** (macOS) or **Ctrl+I** (Windows/Linux), or click the AI icon in the top navigation bar.

## How It Works

<Steps>
  ### Describe your rule in the AI chat panel

  Open the AI assistant and describe what you want. For example:

  * "Create a decisioning gate for customers aged 18 or older"
  * "Build a rule targeting users who spent more than \$200 in the last 30 days"
  * "Set up a rule excluding customers who haven't converted on credit card offers"
  * "Create a rule for credit score above 650 and income at least 50000"

  ### AI parses into structured entities

  The AI calls `POST /api/v1/ai/parse-rule` with your text and your tenant's schema context (field names from all your Data Schemas). The parser produces one or more structured entities, each with a `type`, `name`, and `payload`.

  The parser supports three entity types:

  | Entity Type          | When Generated                                     | Example                                                                                 |
  | -------------------- | -------------------------------------------------- | --------------------------------------------------------------------------------------- |
  | `qualification_rule` | Age, spend, score, or attribute-based conditions   | "customers over 25" produces `age >= 25`                                                |
  | `contact_policy`     | Negation conditions (haven't, hasn't, never, etc.) | "haven't converted on credit card offers" produces an outcome-based policy              |
  | `behavioral_metric`  | Time-windowed aggregations                         | "spent \$500 in the last 90 days" produces a sum metric on revenue with a 90-day window |

  ### Preview the proposed entities

  The AI assistant shows a preview card with the structured definitions — field mappings, operators, and values. Review the details to make sure the AI interpreted your description correctly. Warnings are shown if referenced fields are not found in your schemas.

  ### Approve or cancel

  Click **Approve** to create the entities, or **Cancel** to refine your description. Created entities start in draft status and appear in their respective lists.
</Steps>

## Supported Patterns

The AI rule parser understands a wide range of natural language patterns. It uses LLM-powered parsing with a deterministic regex-based fallback if the LLM is unavailable.

### LLM-Powered Parsing

When the LLM is available, the parser uses an AI-SDK structured-object call with schema context to interpret any natural language description. The LLM receives:

* Your text description
* Available schemas and their field names
* Max conditions per rule (configurable, default: 5)
* Allowed operators (configurable, default: equals, gt, lt, gte, lte, contains, in)

### Heuristic Fallback Patterns

If the LLM call fails, the parser falls back to regex-based heuristics that handle these patterns:

| Pattern             | Example                                                  | Parsed As                                                                                      |
| ------------------- | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| Age comparisons     | "over 25", "aged 18 or older", "above 30"                | `qualification_rule` with `customer.age >= 25`                                                 |
| Spend thresholds    | "spent more than $500", "revenue above $1,000"           | `qualification_rule` with `customer.total_spend >= 500`                                        |
| Time-windowed spend | "spent \$500 in the last 90 days"                        | `behavioral_metric` (sum of revenue, 90d window) + `qualification_rule` referencing the metric |
| Negation            | "haven't converted", "hasn't clicked", "never purchased" | `contact_policy` with outcome-based suppression                                                |
| Category detection  | "credit card offers", "loan offers", "insurance"         | Scope applied to the contact policy entity                                                     |

The heuristic parser also warns when referenced fields (income, loyalty, score, tier, segment, status, balance) are not found in available schemas, and flags ambiguous terms like "VIP" if no matching field exists.

## Batch Creation

You can describe multiple rules in a single message. The AI parses all entities from the description and shows a preview for each one:

```
Create rules for:
- Customers aged 18 or older
- Credit score above 650
- Spent more than $1,000 in the last 30 days
- Haven't converted on the auto loan offer
```

This produces four entities: two decisioning gates, one behavioral metric (with a linked decisioning gate), and one contact policy.

## Schema Context

The rule parser automatically loads your tenant's Data Schemas and passes the field names to the AI. This means:

* Field references are validated against your actual data model
* Warnings are generated for fields that do not exist in any schema
* The AI can suggest the correct field name if a close match exists

## Configurable Constraints

The rule parser has three built-in constraints. **Max Conditions** and **Allowed Operators** honor the per-tenant Rule Building overrides configured in [AI Configuration](/ai-ml/ai-configuration): the `parse-rule` endpoint loads them from tenant settings and passes them into the parser at request time, falling back to the defaults below when a tenant has not set an override. **Field Type Constraints** is stored in tenant settings but is not yet referenced by the parser.

| Parameter              | Default                                | Effect                                                                           |
| ---------------------- | -------------------------------------- | -------------------------------------------------------------------------------- |
| Max Conditions         | 5                                      | Limits how many conditions a single rule can have. Honors the tenant override.   |
| Allowed Operators      | equals, gt, lt, gte, lte, contains, in | Restricts which comparison operators the AI can use. Honors the tenant override. |
| Field Type Constraints | null (all types)                       | Defined in tenant settings; not currently referenced by the parser               |

## Tips

* **Be specific** — Include the field name, comparison, and value. Vague descriptions like "good customers" cannot be parsed into specific conditions.
* **Break complex logic apart** — Deeply nested conditions (e.g., "(A AND B) OR (C AND D)") work better as separate rules combined at the Decision Flow level.
* **Numeric precision** — Currency symbols and comma separators are handled automatically. "\$1,000" becomes `1000`.
* **Time windows create metrics** — When you mention "in the last N days", the parser creates a behavioral metric to track the aggregation, then creates a decisioning gate that references that metric.

<Tip>
  The AI chat panel can also be accessed via MCP from external tools like Claude Code and Cursor. See the [MCP Server Reference](/integrations/mcp) for details.
</Tip>

## Next Steps

<CardGroup cols={3}>
  <Card title="Decisioning Gates" icon="filter" href="/decisioning/qualification-rules">
    Learn how decisioning gates work in Decision Flows.
  </Card>

  <Card title="AI Assistant" icon="message-bot" href="/ai-ml/ai-assistant">
    Learn more about the built-in AI assistant.
  </Card>

  <Card title="AI Configuration" icon="gear" href="/ai-ml/ai-configuration">
    Configure rule building parameters.
  </Card>
</CardGroup>
