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

# Auto-Apply Rules

> Attach labels to a session automatically when your messages match a regular expression.

Auto-apply rules let a [label](/labels/overview) tag itself. Instead of picking labels by hand, you attach one or more regex rules to a label; when a message you send matches, Synti applies the label — and, for [typed labels](/labels/overview#typed-values), extracts a value from the match. It's the fastest way to keep sessions organized as you work, especially for recurring identifiers like ticket numbers, order IDs, or amounts.

## Defining rules

Rules live in the `autoRules` array on a label inside your workspace's label config:

```text theme={null}
~/.synti/workspaces/{workspace-id}/labels/config.json
```

Each rule has these fields:

| Field           | Required | Purpose                                                                         |
| --------------- | -------- | ------------------------------------------------------------------------------- |
| `pattern`       | Yes      | JavaScript regular expression, using capture groups to pull out the value       |
| `valueTemplate` | No       | Builds the value from captures with `$1`, `$2`, … — defaults to the first group |
| `flags`         | No       | Regex flags; defaults to `gi`, and `g` is always enforced                       |
| `description`   | No       | A human-readable note explaining what the rule matches                          |

```json theme={null}
{
  "id": "ticket",
  "name": "Ticket",
  "valueType": "string",
  "autoRules": [
    {
      "pattern": "\\b(JIRA-\\d+)\\b",
      "description": "Match Jira ticket references like JIRA-1234"
    }
  ]
}
```

Here a message containing `JIRA-1234` attaches the label as `ticket::JIRA-1234`.

## When rules run

Synti evaluates rules automatically whenever you send a message, including messages that were queued and sent later. It only scans **your** messages — assistant replies and tool output are never matched, so the agent's own text can't trigger a label.

Before matching, Synti strips fenced code blocks (\`\`\`) and inline code (`` ` ``) from the message. That keeps sample data, logs, and snippets from tripping rules they weren't meant to.

## How matches are processed

All rules across all labels are evaluated together against the cleaned message. A few guardrails shape the result:

* **Match cap.** A single message produces at most **10** matches, which prevents a bulk paste from exploding into dozens of labels.
* **Deduplication.** If a session already carries a given label + value pair, a repeat match won't add it again.
* **Aggregation.** Multiple rules on one label all contribute; their matches combine.

### Value normalization

Extracted values are normalized according to the label's `valueType`:

* **string** — passed through unchanged.
* **number** — currency symbols and commas are stripped, and shorthand suffixes expand, so `1.5M` becomes `1500000` and `50k` becomes `50000`.
* **date** — passed through unchanged (author it in ISO `YYYY-MM-DD` form).

```json theme={null}
{
  "id": "amount",
  "name": "Amount",
  "valueType": "number",
  "autoRules": [
    { "pattern": "\\$([\\d.,]+[kKmM]?)", "valueTemplate": "$1" }
  ]
}
```

## Validation and safety

Synti validates patterns both when you save the config and again at runtime. An invalid regex is logged and skipped rather than breaking evaluation, and save-time validation additionally flags patterns vulnerable to catastrophic backtracking (ReDoS) so a slow expression can't stall matching.

<Tip>
  Write specific patterns with word boundaries (`\b`) and anchored formats. A rule like `\b(ORD-\d{6})\b` is both faster and less likely to produce false positives than a loose one.
</Tip>

<Note>
  Auto-rules only apply labels — they never remove them. To take a label off a session, remove it manually or ask the agent.
</Note>
