ValidationAction function not being read

Hi!

A slot was defined in domain and filled ‘from_entity’. ‘ValidatePredefinedSlots’ Class was created to validate the slot value.

Below are the details:

domain: slots: var_num: type: text mappings: - type: from_entity entity: var_num intent: compare_indepgroups not_intent: info_test

actions:

  • action_validate_slot_mappings
  • action_compare_indepgroups

responses: utter_ask_var_num:

  • text: How many independent groups you want to compare?

action.py

class ValidatePredefinedSlots(ValidationAction):

    def validate_var_num(
        self,
        slot_value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict,
    ) -> Dict[Text, Any]:
        """Validate var_num."""
        num = tracker.get_slot("var_num")

        if num is None:
            dispatcher.utter_message(response="utter_ask_var_num")
            return {"var_num": None}
        return {"var_num": num}
class ActionCompareIndepgroups(Action):
    def name(self):
        return 'action_compare_indepgroups'

    def run(self,
           dispatcher: CollectingDispatcher,
           tracker: Tracker,
           domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        
        var_num = tracker.get_slot('var_num')
        alpha = ['one', 'two', '1', '2']

        if var_num in alpha:
            dispatcher.utter_message(response="utter_compare_2indepgroups")
        else:
            dispatcher.utter_message(response="utter_compare_MoreThan3indepgroups")
      
        return [SlotSet("var_num","")]

rules:

  • rule: Compare Independent Groups steps:
    • intent: compare_indepgroups
    • action: action_validate_slot_mappings
    • action: action_compare_indepgroups

Problem: The action_validate_slot_mappings is being called, but the function did not run. Did I miss something?

You seem to be missing the name of the action action_validate_slot_mappings on your class ValidatePredefinedSlots.

This is how your current code looks like:

class ValidatePredefinedSlots(ValidationAction):

    def validate_var_num(
        self,
        slot_value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict,
    ) -> Dict[Text, Any]:
        """Validate var_num."""
        num = tracker.get_slot("var_num")

        if num is None:
            dispatcher.utter_message(response="utter_ask_var_num")
            return {"var_num": None}
        return {"var_num": num}

This is my suggestion:

class ValidatePredefinedSlots(ValidationAction):
    def name(self) -> Text:
        return "action_validate_slot_mappings"

    def validate_var_num(
        self,
        slot_value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict,
    ) -> Dict[Text, Any]:
        """Validate var_num."""
        num = tracker.get_slot("var_num")

        if num is None:
            dispatcher.utter_message(response="utter_ask_var_num")
            return {"var_num": None}
        return {"var_num": num}

All I did was add the following code to your class ValidatePredefinedSlots:

    def name(self) -> Text:
        return "action_validate_slot_mappings"

Let me know if this works for you.

hi @DARKSUPLA, thanks for your reply! Unfortunately, that did not work.