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

# Custom logic

> Label every call with one outcome using if/then rules you write, with no code and no model cost.

Custom logic labels every call with your own if/then rules. No code and no AI are involved, so you can see each call's outcome, filter on it, and check why it matched.

It's a kind of value inside a [disposition](https://docs.bland.ai/agents/dispositions.md). You write an ordered list of rules. Each rule gives the call a label, such as Appointment booked or Voicemail, and the first rule that matches decides the call's label.

> [!NOTE]
>
> Custom logic is switched on per organization, on top of [Dispositions](https://docs.bland.ai/agents/dispositions.md). If **Logic** is missing from the **Add value** menu, it isn't on for your organization yet. Your Bland partner can ask for it.

## Prerequisites

* A disposition on the agent. See [Build one](https://docs.bland.ai/agents/dispositions.md#build-one)
* An owner, admin, operator or prompter role to edit it, and an owner, admin or operator role to publish it. See [Roles and permissions](https://docs.bland.ai/platform/roles-and-permissions.md)

## How rules decide a label

* Rules are checked from the top. The first rule that matches gives the call its label, and the rest are skipped.
* A rule matches when **All conditions are true**, or when **At least one condition is true**. You choose per rule.
* **Unclassified** is always last. A call that matches no rule gets it.
* Custom logic runs after every other value in the disposition, so a rule can read their results.
* Rules run without a model. The cost estimate for a custom logic value is \$0.

Because the first match wins, put narrow rules above broad ones. "The booking tool confirmed" belongs above "The call lasted under 20 seconds", or a short call that booked would land on the second.

## Build it

**1. Add a custom logic value**

In your disposition, open **Add value** and choose **Logic**, then **Create custom logic**. Give the value a name, such as Call outcome. Its key is how the result is named in the payload.

**2. Add rules**

Press **Add rule**. A value holds up to 23 rules. In the rule drawer:

* **Conditions**: what has to be true about the call. Add as many as you need.
* **Condition matching**: **All conditions are true** or **At least one condition is true**.
* **Label**: the name shown on the call, and a key with lowercase letters, numbers and underscores, up to 64 characters.
* **Description (optional)**: when the label applies. It's shown in conversation logs.
* **Classification (optional)**: one of **Goal achieved**, **Right party contact**, **Goal lost** or **No contact**. It appears next to the label and in the result.

Each rule reads in the list as "If ...", followed by its label.

**3. Order them**

Drag rules to change their order, or choose **Move up** or **Move down** from a rule's menu.

**4. Publish**

Publish the disposition. The rules start labeling calls the agent takes from then on. To label calls it already took, run a [backfill](https://docs.bland.ai/agents/dispositions.md#run-it-on-past-calls).

### Start from a template

Two ways to skip writing rules from scratch:

* Before you add your first rule, **Templates** in the custom logic editor adds a starter set of rules: **Outbound sales** or **Inbound support**.
* When you create a disposition, the **Outbound sales call outcomes** and **Inbound support call outcomes** templates create a whole disposition with a custom logic value already in it. The outbound template also includes an Interest value that a model reads from the transcript, so that disposition does have a model cost.

Starter rules refer to tool and variable names. Change them to match your agent, or the rules won't match anything.

### Copy rules from another disposition

The **Logic** menu also lists the custom logic in the agent's other dispositions. Pick one to copy its rules into this disposition. The copy is independent, so later edits to either one don't affect the other. If the copied rules read a disposition value this disposition doesn't have, the editor names it.

## Conditions

| Field | Comparisons | Notes |
| - | - | - |
| Call status | is any of, is none of | Completed, No answer, Busy, Failed, Canceled |
| Answered by | is any of, is none of | Person, Voicemail, Unknown |
| Ended by | is any of, is none of | Caller, Agent |
| Call length | is less than, is more than, is between | In seconds. "Is between" includes both limits |
| Transfer | happened, did not happen | |
| Pathway tag | includes, does not include | A tag seen on this agent's calls, or a tag name you enter |
| Variable | equals, does not equal, contains, is any of, is greater than, is less than, is set, is not set | Names are case-sensitive |
| Tool | Completed without error, Response matches, failed, was blocked, was not called | The tool's last attempt on the call decides |
| Disposition value | Same as Variable | Another value in this disposition, such as a judge's verdict |

For variables and disposition values:

* Text comparisons ignore capitalization and surrounding spaces.
* "Does not equal" also matches a value that isn't set.
* "Is greater than" and "is less than" match only when the value is a number.
* "Is any of" takes up to 20 values.
* A rule can't read another custom logic value, or its own.

### Tool conditions

Enter the tool's exact runtime name. Each comparison checks the tool's last attempt on the call:

| Comparison | Matches when |
| - | - |
| Completed without error | The last attempt returned without an error. That doesn't mean the business action worked. A booking API can answer 200 without booking |
| Response matches | The last attempt succeeded and a response field compares to a value. Enter the field as a JSONPath, as in the tool's response mapping, for example `$.booking.confirmed`. With "equals", leave the value blank to match any non-empty value |
| failed | The last attempt failed. Narrow it with an HTTP status such as `503` or a class such as `5xx`, or leave it blank to match any failure |
| was blocked | The agent refused to run the tool, for example because the caller wasn't verified or a required input was missing. Leave the reasons empty to match any reason |
| was not called | The agent never tried to run the tool. A blocked attempt counts as called |

## Example

A dental front desk that books cleanings with a `book_appointment` tool. The tool's response mapping stores `booking_confirmed`, and the agent extracts `caller_intent`.

| # | If | Label | Classification |
| - | - | - | - |
| 1 | Variable `booking_confirmed` equals `true` | Appointment booked | Goal achieved |
| 2 | Variable `booking_confirmed` is set | Booking failed | Goal lost |
| 3 | Variable `caller_intent` equals `pricing` | Price question only | Right party contact |
| 4 | Variable `caller_intent` is any of `not_interested`, `wrong_number` | Not interested | Goal lost |
| 5 | Call length is less than 20 seconds | Hung up early | No contact |
| | No rule matched | Unclassified | |

Rule 2 only catches calls where the tool ran without confirming, because a confirmed booking already matched rule 1.

## See why a call got its label

In [Conversations](https://docs.bland.ai/agents/conversations.md), the value gets a column and a filter named after it, for example Call outcome.

Press a call's label to open its Dispositions section with the rule that matched, for example:

> Rule 1 matched: Variable booking\_confirmed equals true

A call with no matching rule shows "No rule matched."

The filter leaves messaging conversations out, and Export is unavailable while it's on.

## Read the result

The label arrives with the disposition's other results on your post-call webhook. See [Read the results](https://docs.bland.ai/agents/dispositions.md#read-the-results). The value is an object:

```json theme={null}
{
  "key": "call_outcome",
  "state": "produced",
  "value": {
    "code": "appointment_booked",
    "name": "Appointment booked",
    "classification": "goal_achieved"
  }
}
```

* `code` is the matched rule's key, or `unclassified` when no rule matched.
* `classification` is left out when the matched rule has none, and is `unknown` for Unclassified.
* The webhook doesn't say which rule matched. That shows only in Conversations.

## Common failures

> [accordion] Calls I tested in Chat have no label
>
> Custom logic labels calls. A chat in the agent's test panel isn't a call, so nothing runs on it. Place a phone call to test. Custom logic doesn't run on SMS or other messaging conversations either.

> [accordion] The label is Error on calls whose rules use a tool
>
> A tool condition needs the call's complete tool history. When some of that history wasn't recorded, the value errors rather than give a label it can't trust. It does this whenever a tool condition is checked before the call matches a rule, so a tool condition in rule 1 affects every call.
>
> Rules that match before any tool condition still label normally. To avoid the error, map the tool's response to a variable and test the variable, or put tool rules below the rules that catch most calls.
>
> In the webhook, the value arrives with `state` set to `error` and the code `result_error`.

> [accordion] Every call is Unclassified
>
> Check the names in your conditions. Tool and variable names must match the agent exactly, and variable names are case-sensitive. Starter rules from a template use example names until you change them.

> [accordion] A call got a broader label than I expected
>
> An earlier rule matched first. Open the label in Conversations to see which rule it was, then move the narrower rule above it.

## Next steps

> [card] [Dispositions](https://docs.bland.ai/agents/dispositions.md)
>
> Delivery timing, webhooks, testing and backfills.

> [card] [Conversations](https://docs.bland.ai/agents/conversations.md)
>
> Filter calls by label and see the rule that matched.

Docs for agents: [llms.txt](https://docs.bland.ai/llms.txt)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.