Rasa 2.0 Forms does not validate extracted slots and asks the next slot

@akelad need your help here. Thanks

Slots gets extracted but does not get validated using validate_<slot_name> function. Following current guidelines here Forms Logs

2020-10-14 17:06:20 DEBUG rasa.core.processor - Logged UserUtterance - tracker now has 297 events.
2020-10-14 17:06:20 DEBUG rasa.core.policies.rule_policy - Predicted loop ‘order_form’. 
2020-10-14 17:06:20 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_0_RulePolicy 
2020-10-14 17:06:20 DEBUG rasa.core.processor - Predicted next action ‘order_form’ with confidence 1.00. 
2020-10-14 17:06:20 DEBUG rasa.core.actions.forms - Validating user input ‘UserUttered(text: lays, intent: {‘id’: 3152659454284902011, ‘name’: ‘inform’, ‘confidence’: 0.999991774559021}, entities: [{‘entity’: ‘snack’, ‘start’: 0, ‘end’: 4, ‘confidence_entity’: 0.8661425709724426, ‘value’: ‘lays’, ‘extractor’: ‘DIETClassifier’}])’. 
2020-10-14 17:06:20 DEBUG rasa.core.actions.forms - Trying to extract requested slot ‘snack’ … 
2020-10-14 17:06:20 DEBUG rasa.core.actions.forms - Got mapping ‘{‘type’: ‘from_entity’, ‘entity’: ‘snack’}’ 
2020-10-14 17:06:20 DEBUG rasa.core.actions.forms - Successfully extracted ‘lays’ for requested slot ‘snack’ 
2020-10-14 17:06:20 DEBUG rasa.core.actions.forms - Validating extracted slots: {‘snack’: ‘lays’} 
2020-10-14 17:06:20 DEBUG rasa.core.actions.action - Calling action endpoint to run action ‘validate_order_form’. 
2020-10-14 17:06:20 DEBUG rasa.core.actions.forms - Request next slot ‘size’

and My custom action:

from typing import Dict, Text, List

from rasa_sdk import Tracker
from rasa_sdk.events import EventType
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk import Action
from rasa_sdk.events import SlotSet
from typing import Text, List, Any, Dict
from rasa_sdk import Tracker, FormValidationAction
from rasa_sdk.types import DomainDict
from rasa.shared.core.domain import Domain

class ActionSwitchFAQ(Action):
    def name(self) -> Text:
        return "action_switch_faq"

    def run(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> List[EventType]:
        return [SlotSet("detailed_faq", not tracker.get_slot("detailed_faq"))]


class ValidateOrderForm(FormValidationAction, Action):
    def name(self) -> Text:
        """Unique identifier of the form"""

        return "validate_order_form"
    
    def run(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> List[EventType]:
        # dispatcher.utter_message("validate_some_slot")
        # return [SlotSet("some_slot", "sdk")]
        return []

    def validate_snack(
        self,
        slot_value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict,
    ) -> Dict[Text, Any]:
        """Validate cuisine value."""
        
        print("Slot Value=", slot_value)
        if slot_value == "fries":
            print("validation succeeded")
            return {"snack": slot_value}
        else:
            print("validation failed")
            # user will be asked for the slot again
            return {"snack": None}
    
    def validate_size(
        self,
        slot_value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict,
    ) -> Dict[Text, Any]:
        """Validate cuisine value."""
        
        print("Slot Value=", slot_value)
        if slot_value == "large":
            print("validation succeeded")
            return {"size": slot_value}
        else:
            print("validation failed")
            # user will be asked for the slot again
            return {"size": None}   `

Could you share the logs of your action server? It seems like it does call your action server to validate the slots

Logs before filling the snack slot

2020-10-14 17:32:58 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
2020-10-14 17:32:58 INFO     rasa_sdk.executor  - Registered function for 'action_switch_faq'.
2020-10-14 17:32:58 INFO     rasa_sdk.executor  - Registered function for 'validate_order_form'.
2020-10-14 17:32:58 INFO     rasa_sdk.endpoint  - Action endpoint is up and running on http://localhost:5055
validate_order_form Run Called

Logs after i enter the value for snack slot

2020-10-14 17:32:58 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
2020-10-14 17:32:58 INFO     rasa_sdk.executor  - Registered function for 'action_switch_faq'.
2020-10-14 17:32:58 INFO     rasa_sdk.executor  - Registered function for 'validate_order_form'.
2020-10-14 17:32:58 INFO     rasa_sdk.endpoint  - Action endpoint is up and running on http://localhost:5055
validate_order_form Run Called
validate_order_form Run Called

ahhh @noman it’s because you overwrote the run() function, which now doesn’t do anything. If you remove it I believe it should work

And you should only need to subclass the FormValidationAction so that it’s class ValidateOrderForm(FormValidationAction)

The default implementation of the run method is listed here

1 Like

ahan ok but to add custom slot mappings and require extra slots we need to override run function as stated here Forms. Then in this case what will we do?

Then you subclass a normal Action, and define the validation logic there. You can find an example in Sara, our demo bot, here - keeping in mind that the method has been renamed to tracker.slots_to_validate. The example is still in process of being updated

In helping you out with this I realise that that implementation isn’t ideal, and the docs are also a little bit confusing! Will talk to our team on how to address this :slight_smile:

1 Like

ok Thanks. @akelad can i keep using FormAction from rasa_sdk with rasa==2.0?

Yeah it would be great :slight_smile:

hm, i think it’s still gonna work for now, but we will deprecate it eventually. So it’s better to migrate eventually. Are there any particular parts you’re struggling with?

1 Like

Hmm ok. Right now i was facing the problem in validation, if i face any while exploring rasa==2.0, will ping you. Thanks for the help.

1 Like

Of course, even after migration, there is a bug in Rasa 2.0 and extracted slots will get again ignored, and the form will ask again for the slots.

Currently there is no way to get this working, we are awaiting for a fix.

@petasis not sure what you mean, as far as I understood your particular issue is with slots from the trigger message. As already mentioned, we’re working on looking into this and will update you when there’s an update. Repeatedly posting about this isn’t going to speed things up.

If you are talking about a different issue than I assumed, then please feel free to open another post so that we can address that separately.

No, I am talking about a different issue, the slots of trigger messages is the bug that makes my bot unusable. I started migration to rasa 2.x on September 28, having a deadline for a demo on October 5. Then I realised that it was not my fault my forms were not working, I updated from rc3 to rc4, found a workround for rc4 on October 7, and on October 8 you released version 2.0. Which changed again how forms should work (from rc4), I updated again my bot, but my forms still do not work, and I cannot find a work around. 7 days later, I still have no solution, no demo, and no plan for a fix from rasa.

What should I do? Go back to 2.0.rc4? Go back to 1.x?

(And if you remember this thread Rasa 2.0, how are forms working?, the problem exists for almost 30 days, and I was hopping 2.0 would fix it - which didn’t -, and the bug has been closed). I really do not know how to proceed.

I’m not sure what you mean, that sounds like the issue I was talking about? The PR submitted that you linked to did fix the issue for our bots. As I asked in the other thread, it would be great if you can open a new post with all the details related to your issue, since that thread has gotten confusing, with other peoples issues, and also the data being in various different forum posts.

btw if you can’t share your code publicly, feel free to email support@rasa.com and we can help you that way