Failed to extract slot email_message with action email_form


I am new to rasa framework and have been trying to work around with simple bot to extract some information and send email by taking in relevant information for sending email

I am getting this error while filling slot in form. Please help me to identify the error

Relevant files are attached below:

config.yml (318 Bytes) (2.7 KB)

domain.yml (1.3 KB) (1.0 KB)

from typing import Dict, Text, Any, List, Union, Optional

from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher from import SlotSet from import AllSlotsReset from rasa_sdk.forms import FormAction import smtplib, ssl from email.message import EmailMessage #import getpass

class ActionGetProfitValue(Action): def name(self) -> Text: return “action_ask_profit”

def run(self, dispatcher, tracker, domain):
    dept_profit = {"sales" : 130000, 
                   "finance" : 80000, 
                   "IT" : 95000, 
                   "marketing" : 150000,
                   "logistics" : 50000}
    dept = tracker.get_slot('department_name')
        if(dept==None or dept==''):
            dispatcher.utter_message("Profit amount for all department is {}".format(sum(dept_profit.values())))
            dispatcher.utter_message("Profit amount for {} is {}".format(dept, dept_profit[dept]))
        dispatcher.utter_message("'{}' is not a valid entry".format(dept))
    return [SlotSet("department_name", None)]

class EmailFormAction(FormAction): def name(self): return “email_form”

def required_slots(tracker):
    """A list of required slots that the form has to fill"""
    return ["email_recipient","email_subject","email_message"]

def submit(self, dispatcher, tracker, domain):
    """Define what the form has to do
    after all required slots are filled"""
    dispatcher.utter_message("all slots have been filled")
    # utter submit template
    dispatcher.utter_template("utter_email_sent", tracker)
    return [AllSlotsReset()]

1 Like

Have you defiend “slot_mappings” after defining “required_slots” ?

Also make sure action server is up…

For example

def slot_mappings(self):
    # type: () -> Dict[Text: Union[Dict, List[Dict]]]
    """A dictionary to map required slots to
        - an extracted entity
        - intent: value pairs
        - a whole message
        or a list of them, where a first match will be picked"""

    return {"email_recipient": [self.from_entity(entity="email_recipient"),
            "email_subject": [self.from_entity(entity="email_subject"),
            "email_message": [self.from_entity(entity="email_message"),

Well, I tried it but still it doesn’t seem to work.

btw, is it necessary to use slot_mapping or is it optional? I think entities with the same name pick the slots themselves without defining slot mapping

Hello @zain could you share an example conversation which I could use to reproduce and possibly spot an issue?

Thanks for replying @Juste, example conversation is attached below:

Please let me know if you require any further details

Hey @zain. I just looked into your nlu model and I am pretty sure the problem is there. I found only one example an input which contains email_message entity. It’s definitely not enough for your bot to learn how to extract it properly. Also, that one example is more like place holder rather than an actual example. I would suggest revising your NLU data and adding more actual examples of how user would provide the email_message and test how the NLU model performs in extracting that entity


@Juste What if the user himself never will mention his mail ID or other entities in the first sentence? How do we make Rasa ask for entity one by one even though RASA does not recognize the entity? i.e Any data i.e entered needs to be captured into respective slots without RASA recognizing them.

Hey @lohith.arcot. I think this is the best use case for the Rasa forms - you can define which slots are required and must be filled before an assistant can run a specific action. Until all required slots are populated, an assistant will ask the user for those details. We actually wrote a tutorial on Rasa forms, I hope it helps: Building contextual assistants with Rasa Forms

1 Like

Made it work with your help. thanks a ton @Juste

1 Like