Slot type List and Text

Hello. Slot type list changes to text and text changes to list based on input. For example if I create a text slot and I extract 2 entities, slot is filled as list → slot: [‘x’, ‘y’]. Also when I create list slot and extract 1 entity, slot is filled as text → slot: x. I want it to be list even if I extract 1 entity, so I can process it in my custom action without checking the type. What is the point defining text and list slots if their type is decided based on input?

Also is there a way to append to a list slot if it is not null, instead of overriding value

1 Like

I’m disappointed that you didn’t get a response yet since this is exactly where I’m stuck. Did you ever find what you needed?

1 Like

I am checking the slot value’s type in my custom action.

Yeah. That’s what I’m doing to. I was hoping that there was a way to make it happen via the slot definitions or something.

thanks for raising this, I’m just looking at the code here and it definitely looks like the behaviour is determined by the slot’s type and not by the type of the extracted entity. Can you please share a minimal example?

@amn41

I’ll add my example below.

nlu.yml

version: "2.0"

nlu:
- intent: bot_challenge
  examples: |
    - are you a bot?
    - are you a human?
    - am I talking to a bot?
    - am I talking to a human?

- intent: pizza
  examples: |
    - I want a [pepperoni](toppings) and [mushroom](toppings) pizza
    - I want a [pepperoni](toppings) pizza

- lookup: toppings
  examples: |
    - pepperoni
    - mushroom

domain.yml

version: "2.0"

intents:
  - pizza
  - toppings
  - bot_challenge

responses:

  utter_pizza:
  - text: "pizza! {toppings} -- {action_toppings}"

actions:
- utter_pizza
- action_pizza_action

slots:
  toppings:
    type: list
  action_toppings:
    type: text

entities:
- toppings
- action_toppings

forms:
  order_pizza_form:
    toppings:
    - entity: toppings
      type: from_entity

session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true

rules.yml

version: "2.0"

rules:

- rule: Order Pizza Form
  steps:
  - intent: pizza
  - action: order_pizza_form
  - active_loop: order_pizza_form

- rule: Ordering Pizza
  condition:
  - active_loop: order_pizza_form
  steps:
    - action: order_pizza_form
    - active_loop: null
    - slot_was_set:
      - requested_slot: null
    - action: action_pizza_action
    - action: utter_pizza

and just for completeness:

actions.py

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet


import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level='DEBUG')
logger.info("LOG")

class PizzaAction(Action):


    def name(self):
        return "action_pizza_action"

    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain):
        print('zap', tracker.slots)
        toppings = tracker.slots.get('toppings')
        print(toppings)
        return [SlotSet('action_toppings',  toppings)]

What happens in Interactive mode is this:

 3    slot{"toppings": ["pepperoni"]}                                                   
      order_pizza_form 1.00                                                             
      active_loop{"name": "order_pizza_form"}                                           
      slot{"toppings": ["pepperoni"]}                                                   
      slot{"toppings": "pepperoni"}                                                     
      slot{"requested_slot": null}                                                      
      active_loop{"name": null}                                                         


Current slots: 
        toppings: pepperoni, action_toppings: None, requested_slot: None, session_started_metadata: None

It starts off as a list, but it turns into a string somewhere only if the list contains one item.

This does not happen if there is more than one item in the list.

1 Like

thank you! was able to reproduce and filed a bug form replaces list slot with length 1 with the item in the list · Issue #8364 · RasaHQ/rasa · GitHub

1 Like

@alperkaan @boristhescot this has been fixed fix slot filling for `ListSlot`s in case only a single matching entity was extracted by wochinge · Pull Request #8675 · RasaHQ/rasa · GitHub