Text slot is sometimes a string and sometimes a list of strings

I have a slot filled with SpaCy which is supposed to be a text slot.

Usually it gets filled with a string. Sometimes it gets filled with a list of strings, like in this example:

Blockquote 2021-04-18 22:40:11 DEBUG rasa.core.processor - Received user message ‘I’m from Austin, Texas’ with intent ‘{‘id’: -527251386905759125, ‘name’: ‘bot_challenge’, ‘confidence’: 0.8819067478179932}’ and entities ‘[{‘entity’: ‘GPE’, ‘value’: ‘Austin’, ‘start’: 9, ‘confidence’: None, ‘end’: 15, ‘extractor’: ‘SpacyEntityExtractor’}, {‘entity’: ‘GPE’, ‘value’: ‘Texas’, ‘start’: 17, ‘confidence’: None, ‘end’: 22, ‘extractor’: ‘SpacyEntityExtractor’}]’

2021-04-18 22:40:11 DEBUG rasa.core.processor - Current slot values: hometown: [‘Austin’, ‘Texas’]

What’s the proper way to handle this? I would expect if I designate the slot as a text slot, it won’t sometimes be a list. This causes an exception in my action handler.

Hey @ivanmkc, I guess the slot becomes a list when there are multiple entities of the same type in one utterance. I think the discussion here will help you, and I’m curious to hear any followup questions :slightly_smiling_face:

Thanks, I’ve taken an extensive look at the Rasa code.

My opinion is that it is an unfortunate design decision as the types can change at will, requiring runtime type checks which are a bad code smell.

@ivanmkc I totally agree that it is unfortunate. How would you improve it, though? I’ve spent some time thinking about this and still can’t see a good solution that would work for most people:

  • picking up all entity instances is, I think, desirable, or else we have to decide which one to pick up (e.g. always the first one)
  • making the slot of type list even if it contains just one item is robust but it means unnecessarily complicating the many cases where you just want to condition on a single, simple value…

In any case, I’m open to other opinions and suggestions – this is an open-source project with contributions always welcome :wink: