I am confused about ‘slot mapping’,in the sectionSlot Filling, the example for the restaurant bot:

def slot_mapping(self):
    # type: () -> Dict[Text: Union[Text, Dict, List[Text, Dict]]]
    """A dictionary to map required slots to
        - an extracted entity
        - intent: value pairs
        - a whole message
        or a list of them, where the first match will be picked"""

    return {"cuisine": self.from_entity(entity="cuisine",
            "num_people": self.from_entity(entity="number"),
            "outdoor_seating": [self.from_entity(entity="seating"),
            "preferences": [self.from_text(intent='inform'),
                                             value="no additional "
            "feedback": [self.from_entity(entity="feedback"),

I can not understand the ‘self.from_entity’ function ,the source code of ‘from_entity’ is:

def from_entity(self,
                    entity,  # type: Text
                    intent=None,  # type: Optional[Union[Text, List[Text]]]
                    not_intent=None  # type: Optional[Union[Text, List[Text]]]
        # type: (...) -> Dict[Text: Any]
        """A dictionary for slot mapping to extract slot value from
            - an extracted entity
            - conditioned on
                - intent if it is not None
                - not_intent if it is not None,
                    meaning user intent should not be this intent
        intent, not_intent = self._list_intents(intent, not_intent)

        return {"type": "from_entity", "entity": entity,
                "intent": intent, "not_intent": not_intent}

According to the source code, self.from_entity(entity=“cuisine”,intent=“inform”) should return “cuisine”,not return the value of cuisine,such as chinese, swedish, If so, what is the role of the ‘from_entity’ function?what is the role of the ‘slot_mapping’ function?

The slot mapping defines how the slots are filled. In your example "num_people": self.from_entity(entity="number")means that the form tries to fill the slot num_people with an extracted entity number. Whenever the form action is called it checks the latest user messages and which entities Rasa NLU extracted. In case Rasa NLU extracted an entity number it will be used to fill the slot num_people.


Hi, suppose in slot mapping I mentioned

“customer_id”: self.from_entity(entity=“customer_id”,not_intent=[‘stop’])

In validation of this slot I mentioned that

    if not self.is_int(value):
        dispatcher.utter_template("utter_invalid_customer_id", tracker)
        return {"customer_id": None}
        return {"customer_id": value}

In story

- form{"name": "bank_form"}
  • form: stop
    • utter_ask_continue
  • form: deny
    • action_deactivate_form
    • form{“name”: null}

So, 1. Once the form is called it will ask user to fill this slot -> this is handled. 2. But when user gives input to this slot as “stop” intent, the form still validates “None” …

How Can I avoid this validation? (when stop intent is uttered)

If a slot is mapped from entity and no entity was extracted, the validate_param method won’t be executed because an Exception will be thrown:

                raise ActionExecutionRejection(
                    "Failed to extract slot {0} "
                    "with action {1}"

You can take a look at this behaviour by commenting it out and returning an empty list. I think then you will get on the right track.

Hi, I commented out ActionExecutionRejection. But My question is : If the input is of “stop” intent, then my bot should not validate this input against that slot.

What changes should i do to implement this behaviour ?


I am on vacation until wednesday. If not already obsolet, I will take a look upon after returning!


1 Like

Hi @JulianGerhard do you know how to solve this problem? Same as Lalit, when the user type stop, it goes back to the slot action instead of stopping the story.