# Failed to extract slot email\_message with action email\_form

**URL:** <https://forum.rasa.com/t/failed-to-extract-slot-email-message-with-action-email-form/13488>\
**Category:** Rasa Open Source\
**Created:** [July 24, 2019, 7:00pm UTC](https://forum.rasa.com/t/failed-to-extract-slot-email-message-with-action-email-form/13488 "2019-07-24T19:00:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![zain](https://avatars.discourse-cdn.com/v4/letter/z/6a8cbe/32.png) [@zain](https://forum.rasa.com/u/zain)\
**Post date:** [July 24, 2019, 7:00pm UTC](https://forum.rasa.com/t/failed-to-extract-slot-email-message-with-action-email-form/13488/1 "2019-07-24T19:00:21Z")

</div>

Hi,

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](https://forum.rasa.com/uploads/short-url/3JkW6kX9SUvNnkWn0cK57YhuxOH.yml) (318 Bytes)

[nlu.md](https://forum.rasa.com/uploads/short-url/weOd6WuLJDDNpFonIrj2i9GasSR.md) (2.7 KB)

[domain.yml](https://forum.rasa.com/uploads/short-url/sKaeSixN6rZCTVOxniSoHDq9GvY.yml) (1.3 KB)

[stories.md](https://forum.rasa.com/uploads/short-url/u0vtMMIBCDJORHfMXgb1gIKFrIO.md) (1.0 KB)

**actions.py**

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

from rasa\_sdk import Action, Tracker from rasa\_sdk.executor import CollectingDispatcher from rasa\_sdk.events import SlotSet from rasa\_sdk.events 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')
    
    try:
        if(dept==None or dept==''):
            dispatcher.utter_message("Profit amount for all department is {}".format(sum(dept_profit.values())))
        else:
            dispatcher.utter_message("Profit amount for {} is {}".format(dept, dept_profit[dept]))
    except:
        dispatcher.utter_message("'{}' is not a valid entry".format(dept))
    return [SlotSet("department_name", None)]

```

class EmailFormAction(FormAction): def name(self): return “email\_form”

```
@staticmethod
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()]

```

 ![Screenshot%20(12)](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/7/747e42e136ce4b990175153d18d7397d4488a4b5.png)

---

<div class="post-metadata">

**Author:** ![adarsh666](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/adarsh666/32/4227_2.png) [@adarsh666](https://forum.rasa.com/u/adarsh666)\
**Post date:** [July 25, 2019, 7:33am UTC](https://forum.rasa.com/t/failed-to-extract-slot-email-message-with-action-email-form/13488/2 "2019-07-25T07:33:55Z")

</div>

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"),
                         self.from_text()],
            "email_subject": [self.from_entity(entity="email_subject"),
                         self.from_text()],
            "email_message": [self.from_entity(entity="email_message"),
                         self.from_text()]}
```

---

<div class="post-metadata">

**Author:** ![zain](https://avatars.discourse-cdn.com/v4/letter/z/6a8cbe/32.png) [@zain](https://forum.rasa.com/u/zain)\
**Post date:** [July 25, 2019, 8:22am UTC](https://forum.rasa.com/t/failed-to-extract-slot-email-message-with-action-email-form/13488/3 "2019-07-25T08:22:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Juste](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/juste/32/15_2.png) [@Juste](https://forum.rasa.com/u/Juste)\
**Post date:** [July 26, 2019, 8:28am UTC](https://forum.rasa.com/t/failed-to-extract-slot-email-message-with-action-email-form/13488/4 "2019-07-26T08:28:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zain](https://avatars.discourse-cdn.com/v4/letter/z/6a8cbe/32.png) [@zain](https://forum.rasa.com/u/zain)\
**Post date:** [July 26, 2019, 12:37pm UTC](https://forum.rasa.com/t/failed-to-extract-slot-email-message-with-action-email-form/13488/5 "2019-07-26T12:37:13Z")

</div>

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

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/2/234cd3d1b0f7ed89e1ad02405fc1965b84a1891f.png)

Please let me know if you require any further details

---

<div class="post-metadata">

**Author:** ![Juste](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/juste/32/15_2.png) [@Juste](https://forum.rasa.com/u/Juste)\
**Post date:** [July 29, 2019, 9:47pm UTC](https://forum.rasa.com/t/failed-to-extract-slot-email-message-with-action-email-form/13488/6 "2019-07-29T21:47:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lohith.arcot](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@lohith.arcot](https://forum.rasa.com/u/lohith.arcot)\
**Post date:** [February 4, 2020, 4:25am UTC](https://forum.rasa.com/t/failed-to-extract-slot-email-message-with-action-email-form/13488/7 "2020-02-04T04:25:01Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Juste](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/juste/32/15_2.png) [@Juste](https://forum.rasa.com/u/Juste)\
**Post date:** [February 4, 2020, 10:32am UTC](https://forum.rasa.com/t/failed-to-extract-slot-email-message-with-action-email-form/13488/8 "2020-02-04T10:32:50Z")

</div>

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](https://blog.rasa.com/building-contextual-assistants-with-rasa-formaction/)

---

<div class="post-metadata">

**Author:** ![lohith.arcot](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@lohith.arcot](https://forum.rasa.com/u/lohith.arcot)\
**Post date:** [February 7, 2020, 9:17am UTC](https://forum.rasa.com/t/failed-to-extract-slot-email-message-with-action-email-form/13488/9 "2020-02-07T09:17:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![poojadeshmukh](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@poojadeshmukh](https://forum.rasa.com/u/poojadeshmukh)\
**Post date:** [September 26, 2020, 2:59am UTC](https://forum.rasa.com/t/failed-to-extract-slot-email-message-with-action-email-form/13488/10 "2020-09-26T02:59:48Z")

</div>

@lohith.arcot, I am facing same issue and unable to fix this. Can you please help me to know how did you fix this?

I have issue with my slot “sleep” below

def slot\_mappings(self) -\> Dict[Text, Union[Dict, List[Dict]]]:

```
    return{

        "confirm_exercise": [

            self.from_intent(intent="affirm",value=True),

            self.from_intent(intent="deny",value=False),

            self.from_intent(intent="inform",value=True),

        ],

        "sleep": [

            self.from_entity(entity="sleep"),

            self.from_intent(intent="deny",value="None")

        ],

        "diet": [

            self.from_text(intent="inform"),

            self.from_text(intent="affirm"),

            self.from_text(intent="deny"),

        ],

        "goal": [

            self.from_text(intent="inform"),

        ]

    }
```
