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:

This basically means that the slots are actually all of type list, even when explicitly set to a non-list type.

So to the developer, we always have to check if the slot value is a list in our action code, since there is no guarantee that it won’t be. Hence, you shouldn’t even have a non-list type as it’s not meaningful.

If you want to have a non-list type, it should always be a non-list, using some sensible default, like highest predicted probability (or similar measure). If that doesn’t make sense, then don’t have a non-list type.

You’re right that there’s no guarantee that the slot won’t be of type slot at some point. Which indeed makes the design flawed. Though let’s keep in mind that in 99% of all cases there’ll be none or just one instance of a particular entity in an utterance… In any case, because this issue requires changes to core user-facing parts of Rasa (in this case how slots behave), we can’t make the changes at any point, but we’re looking into it as part of the next major release, along with some other related improvements to slots – stay tuned!

1 Like

Thanks for the update. Sounds good :slight_smile: