dkbhadeshiya
dkbhadeshiya

Reputation: 179

RASA FormAction ActionExecutionRejection doesn’t re-prompt for missing slot

I am trying to implement a FormAction here, and I’ve overridden validate method.

Here is the code for the same:

def validate(self, dispatcher, tracker, domain):
      logger.info("Validate of single entity called")
      document_number = tracker.get_slot("document_number")
      # Run regex on latest_message
      extracted = re.findall(regexp, tracker.latest_message['text'])
      document_array = []
      for e in extracted:
          document_array.append(e[0])
      # generate set for needed things and
      document_set = set(document_array)
      document_array = list(document_set)
      logger.info(document_set)
      if len(document_set) > 0:
          if document_number and len(document_number):
              document_array = list(set(document_array + document_number))
          return [SlotSet("document_number", document_array)]
      else:
          if document_number and len(document_number):
              document_array = list(set(document_array + document_number))
              return [SlotSet("document_number", document_array)]
          else:
              # Here it doesn't have previously set slot
              # So Raise an error
              raise ActionExecutionRejection(self.name(), 
                                             "Please provide document number")

So, ideally as per the docs, when ActionExecutionRejection occurs, it should utter a template with name utter_ask_{slotname} but it doesn’t trigger that action.

Here is my domain.yml templates

templates:
  utter_greet:
    - text: "Hi, hope you are having a good day! How can I help?"
  utter_ask_document_number:
    - text: "Please provide document number"
  utter_help:
    - text: "To find the document, please say the ID of a single document or multiple documents"
  utter_goodbye:
    - text: "Talk to you later!"
  utter_thanks:
    - text: "My pleasure."

Upvotes: 1

Views: 1449

Answers (1)

Ella Rohm-Ensing
Ella Rohm-Ensing

Reputation: 346

The ActionExecutionRejection doesn't by default utter a template with the name utter_ask_{slotname}, but rather leaves the form logic to allow other policies (e.g. FallbackPolicy) to take action. The utter_ask_{slotname} is the default for the happy path in which it's trying to get a required slot for the first time. This default implementation of the action rejection is there in order to handle certain unhappy paths such as if a user decides they want to exit the flow by denying, or take a detour by chatting, etc.

If you want to implement the template to re-ask for the required slot using the utterance, you could replace the ActionExecutionRejection with dispatcher.utter_template(<desired template name>, tracker). However, this will leave you with no way to exit the form action without validation -- I don't know what your intents are, but perhaps you want to also incorporate some logic based on the intent (i.e. if it's something like "deny", let the ActionExecutionRejection happen so it can exit, it it's an "enter data" type of intent make sure it asks again).

Upvotes: 2

Related Questions