Problem when filling slots with custom form (Failed to extract slot)

Hello,

I’m implementing an action form to collect all the required data for some processing but I got this error:

2020-04-09 09:19:13 ERROR    rasa_sdk.endpoint  - Failed to extract slot type with action places_form
2020-04-09 09:19:13 ERROR    rasa.core.actions.action  - Failed to extract slot type with action places_form

This custom form must collect two required slots: city and type. The first one is collected from an entity of an intent. For example: Give me all places for [Rennes](city). This works fine.

But the previous intent doesn’t contain the type hint and the action form and I want an additional question to be triggered. For example: Which type of places?.

Here is the code of this action form:

class CustomFormAction(FormAction):
  def name(self):
    return ""

  def request_next_slot(
    self,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: Dict[Text, Any],
  ) -> Optional[List[EventType]]:
    """Request the next slot and utter template if needed,
        else return None"""

    for slot in self.required_slots(tracker):
      if self._should_request_slot(tracker, slot):
        # logger.debug(f"Request next slot '{slot}'")
        dispatcher.utter_message(
          template=f"utter_ask_{self.name()}_{slot}", **tracker.slots
        )
        return [SlotSet(REQUESTED_SLOT, slot)]

    return None

class PlacesForm(CustomFormAction):
  def name(self) -> Text:
    return "places_form"

  @staticmethod
  def required_slots(tracker: Tracker) -> List[Text]:
    return ["city", "type"]

  def submit(
    self,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: Dict[Text, Any],
  ) -> List[Dict]:
    city = tracker.get_slot("city")
    print("city : {}".format(city))
    print("domain : {}".format(json.dumps(domain)))

    elements = requests.get("http://...").json()

    dispatcher.utter_message(template="utter_places")
    dispatcher.utter_message(json.dumps(elements))
    return []

Here is the way I defined the associated story:

## places
* places
  - places_form
  - form{"name": "places_form"}

And the places intent:

## intent:places
- Give me places around [Rennes](city)
- What are the places around [Rennes](city)
- I'm looking for places around [Rennes](city)
- Give me all places for [Rennes](city)

I have the FormPolicy in my config.yml file:

policies:
  - name: FallbackPolicy
    nlu_threshold: 0.75
  - name: AugmentedMemoizationPolicy
  - name: FormPolicy
  - name: MappingPolicy
  - name: TEDPolicy
    epochs: 20

Here are the logs regarding the conversation:

Your input ->  Give me all places for Rennes
2020-04-09 09:19:07 DEBUG    rasa.core.tracker_store  - Creating a new tracker for id '8fcaa471f975433ca5e4c1af83b8ca38'.
2020-04-09 09:19:07 DEBUG    rasa.core.processor  - Starting a new session for conversation ID '8fcaa471f975433ca5e4c1af83b8ca38'.
2020-04-09 09:19:07 DEBUG    rasa.core.processor  - Action 'action_session_start' ended with events '[<rasa.core.events.SessionStarted object at 0x7fb3d9ab0e48>, <rasa.core.events.ActionExecuted object at 0x7fb3d9ab0e10>]'.
2020-04-09 09:19:07 DEBUG    rasa.core.processor  - Current slot values: 
	city: None
	requested_slot: None
	type: None
2020-04-09 09:19:08 DEBUG    rasa.nlu.classifiers.diet_classifier  - There is no trained model: component is either not trained or didn't receive enough training data.
2020-04-09 09:19:08 DEBUG    rasa.nlu.selectors.response_selector  - Adding following selector key to message property: default
2020-04-09 09:19:08 DEBUG    rasa.core.processor  - Received user message 'Give me all places for Rennes' with intent '{'name': 'places', 'confidence': 0.9888553619384766}' and entities '[{'entity': 'city', 'start': 31, 'end': 38, 'extractor': 'DIETClassifier', 'value': 'Rennes'}]'
2020-04-09 09:19:08 DEBUG    rasa.core.processor  - Current slot values: 
	city: Rennes
	requested_slot: None
	type: None
2020-04-09 09:19:08 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 5 events.
2020-04-09 09:19:08 DEBUG    rasa.core.policies.fallback  - NLU confidence threshold met, confidence of fallback action set to core threshold (0.3).
2020-04-09 09:19:08 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, None, {}, {'intent_places': 1.0, 'entity_city': 1.0, 'prev_action_listen': 1.0}]
2020-04-09 09:19:08 DEBUG    rasa.core.policies.memoization  - Launch DeLorean...
2020-04-09 09:19:08 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, None, {}, {'intent_places': 1.0, 'entity_city': 1.0, 'prev_action_listen': 1.0}]
2020-04-09 09:19:08 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
2020-04-09 09:19:08 DEBUG    rasa.core.policies.form_policy  - There is no active form
2020-04-09 09:19:08 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_4_TEDPolicy
2020-04-09 09:19:08 DEBUG    rasa.core.processor  - Predicted next action 'places_form' with confidence 0.92.
2020-04-09 09:19:08 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'places_form'.
2020-04-09 09:19:08 DEBUG    rasa.core.processor  - Action 'places_form' ended with events '[BotUttered('Quelle est la valeur du type?', {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, {"city": "Rennes"}, 1586416748.2458563), <rasa.core.events.Form object at 0x7fb3d9a6bcc0>, <rasa.core.events.SlotSet object at 0x7fb3d9ab0da0>, <rasa.core.events.SlotSet object at 0x7fb429a027b8>, <rasa.core.events.SlotSet object at 0x7fb3d9dbb400>]'.
2020-04-09 09:19:08 DEBUG    rasa.core.processor  - Current slot values: 
	city: Rennes
	requested_slot: type
	type: None
2020-04-09 09:19:08 DEBUG    rasa.core.policies.fallback  - NLU confidence threshold met, confidence of fallback action set to core threshold (0.3).
2020-04-09 09:19:08 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, None, {}, {'intent_places': 1.0, 'entity_city': 1.0, 'prev_action_listen': 1.0}]
2020-04-09 09:19:08 DEBUG    rasa.core.policies.memoization  - Launch DeLorean...
2020-04-09 09:19:08 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, None, None, {}]
2020-04-09 09:19:08 DEBUG    rasa.core.policies.memoization  - There is a memorised next action 'action_listen'
2020-04-09 09:19:08 DEBUG    rasa.core.policies.form_policy  - There is an active form 'places_form'
2020-04-09 09:19:08 DEBUG    rasa.core.policies.mapping_policy  - There is no mapped action for the predicted intent, 'places'.
2020-04-09 09:19:08 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_2_FormPolicy
2020-04-09 09:19:08 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2020-04-09 09:19:08 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'.
2020-04-09 09:19:08 DEBUG    rasa.core.lock_store  - Deleted lock for conversation '8fcaa471f975433ca5e4c1af83b8ca38'.
Quelle est la valeur du type?
Your input ->  tt                                                                                                                                                            
2020-04-09 09:19:13 DEBUG    rasa.core.tracker_store  - Recreating tracker for id '8fcaa471f975433ca5e4c1af83b8ca38'
2020-04-09 09:19:13 DEBUG    rasa.nlu.classifiers.diet_classifier  - There is no trained model: component is either not trained or didn't receive enough training data.
2020-04-09 09:19:13 DEBUG    rasa.nlu.selectors.response_selector  - Adding following selector key to message property: default
2020-04-09 09:19:13 DEBUG    rasa.core.processor  - Received user message 'tt' with intent '{'name': 'deny', 'confidence': 0.5609110593795776}' and entities '[]'
2020-04-09 09:19:13 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 13 events.
2020-04-09 09:19:13 DEBUG    rasa.core.policies.fallback  - NLU confidence 0.5609110593795776 is lower than NLU threshold 0.75. 
2020-04-09 09:19:13 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, {}, {'intent_places': 1.0, 'entity_city': 1.0, 'prev_action_listen': 1.0}, {'intent_places': 1.0, 'entity_city': 1.0, 'active_form_places_form': 1.0, 'prev_places_form': 1.0}, {'intent_deny': 1.0, 'prev_action_listen': 1.0, 'active_form_places_form': 1.0}]
2020-04-09 09:19:13 DEBUG    rasa.core.policies.memoization  - Launch DeLorean...
2020-04-09 09:19:13 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, None, {}, {'intent_deny': 1.0, 'prev_action_listen': 1.0}]
2020-04-09 09:19:13 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
2020-04-09 09:19:13 DEBUG    rasa.core.policies.form_policy  - There is an active form 'places_form'
2020-04-09 09:19:13 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_2_FormPolicy
2020-04-09 09:19:13 DEBUG    rasa.core.processor  - Predicted next action 'places_form' with confidence 1.00.
2020-04-09 09:19:13 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'places_form'.
2020-04-09 09:19:13 ERROR    rasa_sdk.endpoint  - Failed to extract slot type with action places_form
2020-04-09 09:19:13 ERROR    rasa.core.actions.action  - Failed to extract slot type with action places_form
2020-04-09 09:19:13 DEBUG    rasa.core.policies.fallback  - NLU confidence 0.5609110593795776 is lower than NLU threshold 0.75. 
2020-04-09 09:19:13 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, {}, {'intent_places': 1.0, 'entity_city': 1.0, 'prev_action_listen': 1.0}, {'intent_places': 1.0, 'entity_city': 1.0, 'active_form_places_form': 1.0, 'prev_places_form': 1.0}, {'intent_deny': 1.0, 'prev_action_listen': 1.0, 'active_form_places_form': 1.0}]
2020-04-09 09:19:13 DEBUG    rasa.core.policies.memoization  - Launch DeLorean...
2020-04-09 09:19:13 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, None, {}, {'intent_deny': 1.0, 'prev_action_listen': 1.0}]
2020-04-09 09:19:13 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
2020-04-09 09:19:13 DEBUG    rasa.core.policies.form_policy  - There is an active form 'places_form'
2020-04-09 09:19:13 DEBUG    rasa.core.policies.ensemble  - Execution of 'places_form' was rejected. Setting its confidence to 0.0 in all predictions.
2020-04-09 09:19:13 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_0_FallbackPolicy
2020-04-09 09:19:13 DEBUG    rasa.core.processor  - Predicted next action 'action_default_fallback' with confidence 1.00.
2020-04-09 09:19:13 DEBUG    rasa.core.processor  - Action 'action_default_fallback' ended with events '[<rasa.core.events.UserUtteranceReverted object at 0x7fb3d99625c0>]'.
2020-04-09 09:19:13 DEBUG    rasa.core.processor  - Current slot values: 
	city: Rennes
	requested_slot: type
	type: None
2020-04-09 09:19:13 DEBUG    rasa.core.policies.fallback  - NLU confidence threshold met, confidence of fallback action set to core threshold (0.3).
2020-04-09 09:19:13 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, None, {}, {'intent_places': 1.0, 'entity_city': 1.0, 'prev_action_listen': 1.0}]
2020-04-09 09:19:13 DEBUG    rasa.core.policies.memoization  - Launch DeLorean...
2020-04-09 09:19:13 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, None, None, {}]
2020-04-09 09:19:13 DEBUG    rasa.core.policies.memoization  - There is a memorised next action 'action_listen'
2020-04-09 09:19:13 DEBUG    rasa.core.policies.form_policy  - There is an active form 'places_form'
2020-04-09 09:19:13 DEBUG    rasa.core.policies.mapping_policy  - There is no mapped action for the predicted intent, 'places'.
2020-04-09 09:19:13 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_2_FormPolicy
2020-04-09 09:19:13 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2020-04-09 09:19:13 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'.
2020-04-09 09:19:13 DEBUG    rasa.core.lock_store  - Deleted lock for conversation '8fcaa471f975433ca5e4c1af83b8ca38'.```

Thanks very much for your help!
Thierry

Hello,

After the bot ask back which type of place?, how do you intend to extract the slot type? My assumption is you want the next input, whatever it is, to become the place’s type, then you need to define the slot_mappings function inside your PlacesForm, for example:

def slot_mappings(self):
      return {
            "city": self.from_entity(entity="city", intent="places),
            "type": self.from_text()
      }

Otherwise, you need to define the type entity in your training data.

Hello,

Thanks very much for your answer! Yes, this fixed my problem.

An additional question would be: is it possible for the “city” slot to add the ability to get either from an entity or from text?

For example, if the “city” slot is missing from the intent “places”, is it possible to trigger a question (like for “type”) to get value from text?

Thierry

Yes it’s possible. Just make the value of return dict from "city": self.from_entity(entity="city", intent="places) into:

"city": [self.from_entity(entity="city", intent="places), self.from_text()]

You can read more at the documentation of form

Thanks very much for the hint and the link to the doc!

我也是想直接从语句当中提取到实体,比如我想给小明打电话,但是提取不到这个实体怎么办