# Slots

Slots are your assistant's memory. They act as a key-value store which can be used to store information the user provided (e.g. their home city) as well as information gathered about the outside world (e.g. the result of a database query).

Slots are defined in the slots section of your domain with their name, [type](/content/docs/reference/primitives/slots/#slot-types/index.html) and default value. Different slot types exist to restrict the possible values a slot can take.

> **Note**: If you decide to fill slots through [response buttons](/content/docs/reference/primitives/responses/#buttons/index.html) where the [payload syntax](/content/docs/reference/primitives/responses/#payload-syntax/index.html) issues `SetSlot` command(s), note that the slot name must not include certain characters such as `(`, `)`, `=` or `,`.

## Slot Types

### Text Slot

A text slot can take on any string value.

- **Example**

```yaml
slots:
    cuisine:
      type: text
```
- **Allowed Values**

Any string

### Boolean Slot

A boolean slot can only take on the values `true` or `false`. This is useful when you want to store a binary value.

- **Example**

```yaml
slots:
    confirmation:
      type: bool
```
- **Allowed Values**

`true` or `false`

### Categorical Slot

A categorical slot can only take on values from a predefined set. This is useful when you want to restrict the possible values a slot can take.

If the user provides a value where the casing does not match the casing of the values defined in the domain, the value will be coerced to the correct casing. For example, if the user provides the value `LOW` for a slot with values `low`, `medium`, `high`, the value will be converted to `low` and stored in the slot.

If you define a categorical slot with a list of values, where multiple of the values coerce to the same value, a warning will be issued and you should remove one of the values from the set in the domain.

- **Example**

```yaml
slots:
    risk_level:
      type: categorical
      values:
      - low
      - medium
      - high
```

### Float Slot

A float slot can only take on floating point values. This is useful when you want to store a number with a decimal point.

- **Example**

```yaml
slots:
    temperature:
      type: float
```

### Any Slot

This slot type can take on any value. This is useful when you want to store any type of information, including structured data like dictionaries.

- **Example**

```yaml
slots:
    shopping_items:
      type: any
```

### List Slot

A list slot can take on a list of values. Note that the list slot type is only supported in [custom actions](/content/docs/reference/primitives/custom-actions/index.html) when building an assistant with [CALM](/content/docs/learn/concepts/calm/index.html). List slots cannot be filled with flows in either the [`collect`](/content/docs/reference/primitives/flow-steps/#collect/index.html) or [`set_slots`](/content/docs/reference/primitives/flow-steps/#set-slots/index.html) flow step types.

## Resetting a slot

To reset a slot in a flow, you can set it to `null` using the [set_slots step](/content/docs/reference/primitives/flow-steps/#set-slots/index.html):

```yaml
- set_slots:
    slot_name: null
```

If you want to reset a slot in a [custom action](/content/docs/reference/primitives/custom-actions/index.html), set its value to `None`.

Slots that are empty are not eligible for [correction](/content/docs/reference/primitives/patterns/#requiring-confirmation/index.html).

### CALM Slot Mappings

New in 3.9.0

When building an assistant with [CALM](/content/docs/learn/concepts/calm/index.html), you can configure slot filling to either use [nlu-based predefined](/content/docs/reference/primitives/slots/#nlu-based-predefined-slot-mappings/index.html) slot mappings or the newly introduced [`from_llm`](/content/docs/reference/primitives/slots/#from_llm/index.html) slot mapping type.

#### NLU-based predefined slot mappings

You can continue using the [nlu-based predefined](https://legacy-docs-oss.rasa.com/docs/rasa/domain#slot-mappings) slot mappings such as [`from_entity`](https://legacy-docs-oss.rasa.com/docs/rasa/domain#from_entity) or [`from_intent`](https://legacy-docs-oss.rasa.com/docs/rasa/domain#from_intent) when building an assistant with CALM. In addition to including tokenizers, featurizers, intent classifiers, and entity extractors to your pipeline, you must also add the [`NLUCommandAdapter`](/content/docs/reference/config/components/nlu-command-adapter/index.html) to the `config.yml` file. The `NLUCommandAdapter` will match the output of the NLU pipeline (intents and entities) against the slot mappings defined in the domain file. If the slot mappings are satisfied, the `NLUCommandAdapter` will issue [`set slot` commands](/content/docs/reference/config/components/llm-command-generators/#command-reference/index.html) to fill the slots.

### Recommendations

1. We recommend adding the [`FallbackClassifier`](https://legacy-docs-oss.rasa.com/docs/rasa/components#fallbackclassifier) to the nlu pipeline to guard against low confidence scores for intents when these are used in `from_intent` slot mappings.
2. We recommend setting [`ask_before_filling: true`](/content/docs/reference/primitives/flow-steps/#always-asking-questions/index.html) at the `collect` flow steps for slots that can be filled by the same entity in the same flow. This prevents the assistant from greedily filling all the slots with the same entity at the same time, when only one of the slots was requested.

#### Initial slot values

You can provide an initial value for any slot in your domain file:

```yaml
slots:
    num_fallbacks:
        type: float
        initial_value: 0
```  
#### Persistence of Slots during Coexistence

In [Coexistence of NLU-based and CALM systems](/content/docs/pro/calm-with-nlu/migrating-from-nlu/index.html) the action [`action_reset_routing`](/content/docs/reference/primitives/default-actions/#action_reset_routing/index.html) resets all slots and hides events from featurization for the NLU-based system policies to prevent them from seeing events that originated while CALM was active. However, you might want to share some slots that both CALM and the NLU-based system should be able to use.

### Real-Time Slot validation

New in 3.12

You can now define validation rules that are strictly independent of business logic directly in the domain file. These rules enforce constraints on slot values when they are collected during the conversation in real time.

You can now validate slot values in real-time as they are collected at any point during a conversation. This can be achieved by adding a `validation` key to the slot definition in the domain file.

```yaml
slots:
    phone_number:
        type: text
        mappings:
          - type: from_llm
        validation:
          rejections:
            - if: not (slots.phone_number matches "^\([0-9]{3}\) [0-9]{3}-[0-9]{4}$")
              utter: utter_invalid_phone_number
            - if: not (slots.phone_number matches "^\d+$")
              utter: utter_invalid_phone
        refill_utter: "utter_refill_phone_number"
``` 
#### Allowed Validation Types

The following validation checks can be defined in the domain file using the [pypred](https://github.com/armon/pypred) library:
- **Regex Matching**: Validate inputs against specific patterns (e.g email addresses, phone numbers, zip codes, registration numbers, etc.)
- **Length Validation**: Ensure input text meets minimum and maximum length requirements (e.g usernames, passwords, IDs)
- **Data Type Validation**: Ensure inputs conform to specific type categories (integers only, numerical values, alphanumeric strings)
- **Range Checks**: For numerical inputs, verify that values fall within a specified range (e.g 18-65 for age, 1-100 for quantity, minimum/maximum thresholds)
- **Date Format Validation**: Validate date inputs against specific formats and logical constraints (e.g YYYY-MM-DD, no future birth dates)
- **List or Enumeration Matching**: Check if inputs match predefined valid options (e.g colors, sizes, categories)
- **Prefix/Suffix Checks**: Verify inputs begin or end with required characters or strings (e.g product codes, reference numbers)
- **Case Sensitivity Checks**: Ensure inputs follow case requirements (e.g lowercase usernames, uppercase codes)
- **Whitespace Validation**: Check for improper spacing patterns in inputs (e.g unwanted leading, trailing, or excessive internal spaces)
- **Special Character Filtering**: Restrict or validate special characters to maintain data integrity and security
