Not able to validate my slot email. Please help

Actually the function for validation is giving me results when the email is written in correct format but when user enters an invalid email it should show a message to “enter the email again” but its not doing that. Instead it replies with some random intetn which it classifies for that input.

my validation funtion ===>

Hi @rohanchoudharyy

after def required_slots add this:

def slot_mappings(self):
    # type: () -> Dict[Text: Union[Dict, List[Dict]]]
    return {"email": [self.from_text()],
                "mobile": [self.from_text()]

Let me know if there is any difference after this.

Hmm :thinking:, I think there is something wrong with the validation function signature. It should have 4 arguments (excluding self) and it should not be returning a list of dict. See the declaration signature here.

@saurabh-m523 noticed that there is something weird in your def validate_email arguments.

You can overwrite it with this:

def validate_email(
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> Dict[Text, Any]: 

And now you don’t need to use value1 = tracker.get_slot('email'). Change value1 to just value

1 Like

Yeah, that is fine but it didn’t resolve my issue. Its not showing the “enter email again” msg. Showing the same error.

I already have mappings done this way :

Although I’ve also tried what you just said and it is not helping. I need to validate my email.

Did you try the slot mapping like i wrote earlier? Because if your mapping for the slot is self.from_text() it should not respond to a random intent that is recognized.

1 Like

Yes, i did that. I was using “value : text” as argument earlier, but then it was not working thats why i moved to “value1 = tracker.get_slot(‘email’)”. But now I have made changes as you said and now the bot is not even accepting the correct email and showing error.

(note : ignore the highlighted part, its an older session)

Not helping brother, tried every thing.

“missing 1 required positional argument: domain” Let’s fix that first.

how to fix that “missing 1 required positional argument: domain” ???

my code is : def validate_email(self, value: Text, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any] ) -> Dict[Text, Any]:


Do you still have that @staticmethod before validate_email ?


Thankyou Kim, I forgot to make it a comment. But the bot is now taking in all valid responses and filling the slots but still not displaying the “enter valid email” msg when inappropriate email format is entered. This is where im stuck :


Try using this, i think regex is true

Hmm :thinking:, I need more info and it is difficult to read screenshots. Please post your story, domain, and action files.

Try this for your first if. You can replace regex with your own but this should work:

value1 = tracker.get_slot('email')
regex = '^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$'
if (,value1)):
1 Like

The error was : expected string or bytes like object. (in the rasa run actions prompt). So i changed the value1’s type as following : “if re.match(r”[a-zA-Z0-9_.±]+@[a-zA-Z]+.[^@]+“, str(value1)):” now its working properly and showing the required msgs. Is it okay if i change its type??


Great to hear it’s working.

You don’t really need to do anything else here but…

I would still delete value1 = tracker.get_slot('email') and replace value1 with just value. Same for value2.

1 Like

okay thanks kim