# Using context variables in tool preset attributes

> Use   context variables in   tool   preset attributes   when a tool needs   values   from the current customer conversation tool configuration or runtime inp

Source: https://help.kustomer.com/en_us/using-context-variables-in-tool-preset-attributes-SkX6ArlQfx

Last updated: 2026-08-11T14:25:32.353Z

Use context variables in tool preset attributes when a tool needs values from the current customer, conversation, tool configuration, or runtime input. Preset attributes are values an admin configures ahead of time so the tool can run with the right information during a conversation.

Context variables are useful when a tool needs values that change at runtime, such as a customer ID, conversation ID, email address, order number, or custom customer attribute.

### Who can use this

User types

Access

Admins

Can configure tool preset attributes that use context variables.

### In this article

*   Reviewing where context variables can be used
*   Choosing the right context variable source
*   Building context variables for OpenAPI tools
*   Building context variables for MCP tools
*   Building context variables for Klass data tools
*   Building a context variable
*   Adding fallback values
*   Troubleshooting context variables

### Reviewing where context variables can be used

Context variables can be used in text-based preset attributes for:

Tool type

Example use

OpenAPI tools

Send the current customer ID in a request body or query parameter.

MCP tools

Pass customer or conversation details to an external MCP tool.

Klass data tools

Look up, create, or update records using customer or conversation data.

Context variables can be used in string values inside preset input values, including nested values such as:

*   Headers.
*   Query parameters.
*   Request bodies.
*   Other string-based preset values.

### Choosing the right context variable source

Before adding a context variable to a tool, decide what value the tool needs at runtime.

Ask:

1.  Does the tool need information from the current customer?
2.  Does the tool need information from the current conversation?
3.  Does the tool need the current tool configuration ID?
4.  Does the AI Agent need to collect the value first?
5.  Should the tool use a fallback value if the field is empty?

Then choose the source that matches the information you need.

Need

Use

Customer profile information

`[[context:customer:<path>]]`

Customer custom attributes

`[[context:customer:custom.<key>]]`

Conversation information

`[[context:conversation:<path>]]`

Current tool configuration ID

`[[context:tool:id]]`

Information collected at runtime

`[[input:<name>:<description>]]`

### Building context variables for OpenAPI tools

Use context variables in OpenAPI tools when an API request needs customer- or conversation-specific data.

For example, an OpenAPI tool might need to send the current customer email address to an external system.

Example request body:

```
{
  "email": "[[context:customer:email]]",
  "customerId": "[[context:customer:id]]",
  "conversationStatus": "[[context:conversation:status]]"
}
```

You can also use context variables in query parameters.

Example query parameter:

```
customer_id=[[context:customer:id]]
```

Or in a header value, if the header accepts text.

```
X-Customer-ID: [[context:customer:id]]
```

### Building context variables for MCP tools

Use context variables in MCP tools when the MCP tool needs information from the current Kustomer context.

For example, an MCP tool that searches an external order system may need a customer email address or an order ID.

Example preset values:

```
{
  "customerEmail": "[[context:customer:email]]",
  "conversationId": "[[context:conversation:id]]"
}
```

If the AI Agent needs to collect a value first, use an input variable.

```
{
  "orderId": "[[input:orderId:the customer's order number]]"
}
```

In this example, the AI Agent supplies the `orderId` value at runtime. The text after the second colon helps describe what value the AI Agent should provide.

### Building context variables for Klass data tools

Use context variables in Klass data tools when you want to create, update, or look up Klass records using information from the current customer or conversation.

For example, a Klass data tool might create a warranty claim record using the current customer ID and a product serial number collected at runtime.

Example preset values:

```
{
  "customerId": "[[context:customer:id]]",
  "customerName": "[[context:customer:name||Guest]]",
  "conversationId": "[[context:conversation:id]]",
  "serialNumber": "[[input:serialNumber:the product serial number]]"
}
```

In this example:

Field

How the value is resolved

`customerId`

Comes from the current customer.

`customerName`

Comes from the current customer, or uses `Guest` if the value is missing.

`conversationId`

Comes from the current conversation.

`serialNumber`

Comes from runtime input.

### Building a context variable

Use this format:

```
[[context:source:path]]
```

Where:

Part

Description

`context`

Marks the value as a context variable.

`source`

The object to pull from, such as `customer`, `conversation`, or `tool`.

`path`

The attribute to use.

Example:

```
[[context:customer:name]]
```

This pulls the `name` value from the current customer.

For customer custom attributes, use:

```
[[context:customer:custom.attributeName]]
```

Example:

```
[[context:customer:custom.loyaltyTier]]
```

This pulls the `loyaltyTier` custom attribute from the current customer.

For tool configuration context, use:

```
[[context:tool:id]]
```

This pulls the current tool configuration ID.

For runtime input, use:

```
[[input:name:description]]
```

Example:

```
[[input:orderId:the customer's order number]]
```

This tells the AI Agent to provide an `orderId` value at runtime.

### Adding fallback values

Add a fallback value when a field should still have a usable value if the customer or conversation data is missing.

Use this format:

```
[[context:customer:name||Guest]]
```

If the customer name exists, Kustomer uses it. If the customer name cannot be resolved, Kustomer uses `Guest` instead.

Fallbacks are useful for optional customer fields, display names, custom attributes, and other values that may not exist on every customer profile.

### Important behavior to know

*   Context variables resolve from preset string values before tool execution.
*   If a token cannot be resolved and no fallback value is provided, Kustomer leaves the token in place and logs a warning.
*   Context variables are intended for text values. Saving them into non-string fields can cause validation problems or leave the tool incomplete.
*   The context variable picker surfaces compatible values for supported preset-attribute editors, including `[[context:tool:id]]`.

### Troubleshooting context variables

#### The tool sent the token text instead of a resolved value

Check the following:

*   The token format is valid.
*   The referenced value exists in the current context.
*   A fallback value is included when the source value may be missing.
*   The value is saved in a supported preset text field.

#### The tool cannot be saved or stays incomplete

Check whether a token was added to a field that does not accept text values. Context variables should be used in text-based preset fields.

#### The wrong value was sent

Confirm that the token references the right source:

*   Use `customer` for customer values.
*   Use `conversation` for conversation values.
*   Use `tool` for the current tool configuration ID.
*   Use `input` for runtime values passed into the tool.
