Slots | Rasa Documentation

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 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 where the payload syntax 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.

slots:
    cuisine:
      type: text

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.

slots:
    confirmation:
      type: bool

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.

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.

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.

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 when building an assistant with CALM. List slots cannot be filled with flows in either the collect or set_slots flow step types.

Resetting a slot

To reset a slot in a flow, you can set it to null using the set_slots step:

- set_slots:
    slot_name: null

If you want to reset a slot in a custom action, set its value to None.

Slots that are empty are not eligible for correction.

CALM Slot Mappings

New in 3.9.0

When building an assistant with CALM, you can configure slot filling to either use nlu-based predefined slot mappings or the newly introduced from_llm slot mapping type.

NLU-based predefined slot mappings

You can continue using the nlu-based predefined slot mappings such as from_entity or 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 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 to fill the slots.

Recommendations

  1. We recommend adding the 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 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:

slots:
    num_fallbacks:
        type: float
        initial_value: 0

Persistence of Slots during Coexistence

In Coexistence of NLU-based and CALM systems the action action_reset_routing 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.

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 library: