# Are slot mappings not used at the beginnig of a Form Action?

**URL:** <https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330>\
**Category:** Rasa Open Source\
**Created:** [July 1, 2019, 9:48pm UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330 "2019-07-01T21:48:34Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![cheloveco](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@cheloveco](https://forum.rasa.com/u/cheloveco)\
**Post date:** [July 1, 2019, 9:48pm UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/1 "2019-07-01T21:48:34Z")

</div>

Hi everyone! I am using Forms for my chatbot and I use a lot of slot\_mappings. When I tested my chatbot it does not extract correctly the entities of the first message but it does for the following ones. I think it is because in the _run_ method, slot\_mappings are not used. Am I wrong? 😬

I think it will be very useful that these mappings are available from the very beginning of the Form.

Greetings!

---

<div class="post-metadata">

**Author:** ![JulianGerhard](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/juliangerhard/32/3781_2.png) [@JulianGerhard](https://forum.rasa.com/u/JulianGerhard)\
**Post date:** [July 2, 2019, 5:18am UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/2 "2019-07-02T05:18:10Z")

</div>

Hi @cheloveco

could you please post the content of your FormAction?

Regards

---

<div class="post-metadata">

**Author:** ![cheloveco](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@cheloveco](https://forum.rasa.com/u/cheloveco)\
**Post date:** [July 2, 2019, 3:43pm UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/3 "2019-07-02T15:43:36Z")

</div>

Hi @JulianGerhard I am not sure what you want me to show you, but here is a part of my Form class:

class BusquedaForm(FormAction):

```
def name(self):
    return "busqueda_form"

def slot_mappings(self):
    return { "estado_Busqueda" : [
                        self.from_intent(intent='el_que_sea', value='Todos'),
                        self.from_entity(entity='estado'),
                        self.from_entity(entity='lugar'),
                        ],

            "municipio_Busqueda" :[
                        self.from_intent(intent='el_que_sea', value='Todos'),
                        self.from_entity(entity='municipio'),
                        self.from_entity(entity='lugar'),
                        ],
            "banios_Busqueda" : [
                        self.from_entity(entity='numero'),
                        self.from_entity(entity='banios'),
                        ],
            "recamaras_Busqueda" :[ 
                        self.from_entity(entity='numero'),
                        self.from_entity(entity = 'recamaras'), 
                        ],
            "tipo_Busqueda" :[
                        self.from_entity(entity = 'tipo')
                        ],
            "propiedad_Busqueda" :[
                        self.from_entity(entity = 'propiedad')
                        ],
            "banios_Busqueda" :[
                        self.from_entity(entity = 'banios'),
                        self.from_entity(entity = 'numero'),
                        ],
            "recamaras_Busqueda" :[
                        self.from_entity(entity = 'recamaras'),
                        self.from_entity(entity = 'numero'),
                        ],
            "alcaldia_Busqueda" : [
                        self.from_entity(entity = 'alcaldia'),
                        ],
            }

@staticmethod
def required_slots(tracker):

    if tracker.get_slot('propiedad_Busqueda') in ["terreno", "bodega"]:            
        
        if tracker.get_slot('estado_Busqueda') == 'Todos':
            return ["tipo_Busqueda", "propiedad_Busqueda"]

        elif tracker.get_slot('estado_Busqueda') == 'Ciudad de México':
            return ["alcaldia_Busqueda", "tipo_Busqueda", "propiedad_Busqueda"]

        else:
            return ["tipo_Busqueda", "estado_Busqueda", "municipio_Busqueda"] 

    else:
        if tracker.get_slot('estado_Busqueda') == 'Todos':
            return ["tipo_Busqueda", "propiedad_Busqueda", "banios_Busqueda", "recamaras_Busqueda"]
        elif tracker.get_slot('estado_Busqueda') == 'Ciudad de México':
            return ["alcaldia_Busqueda", "tipo_Busqueda", "propiedad_Busqueda", "banios_Busqueda", "recamaras_Busqueda",]
        else: 
            return ["tipo_Busqueda", "propiedad_Busqueda", "estado_Busqueda", "municipio_Busqueda", "banios_Busqueda", "recamaras_Busqueda"]

```

The remaining part are validations of several slots, and the submit method.

However I managed to modify the _rasa\_sdk.forms_ module, specifically the _\_activate\_if\_required_ function and now the Form is filling the corresponding slots with the mappings given in the _actions.py_ script, at the first message, the one that activates the Form.

---

<div class="post-metadata">

**Author:** ![erohmensing](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/erohmensing/32/1789_2.png) [@erohmensing](https://forum.rasa.com/u/erohmensing)\
**Post date:** [July 2, 2019, 3:56pm UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/4 "2019-07-02T15:56:48Z")

</div>

@cheloveco when you say if didn’t correctly pick them up, does it pick them up in the wrong format, or does it not pick them up at all? Which version of SDK are you on?

Can you give an example of what the input was, what you wanted picked up, and what you got?

---

<div class="post-metadata">

**Author:** ![cheloveco](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@cheloveco](https://forum.rasa.com/u/cheloveco)\
**Post date:** [July 2, 2019, 4:21pm UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/5 "2019-07-02T16:21:50Z")

</div>

I have these versions of rasa:

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

And this is the example:

I wrote to my chatbot “me gustaria rentar un departamento en la cdmx”, the nlu model does its job fine, it extracts the three enitites I wanted to, namely “tipo”, “propiedad” and “estado”. If you look at the requested slots there are slots named “tipo\_Busqueda”, “propiedad\_Busqueda” and “estado\_Busqueda” which are empty. Also, in the piece of the Form class I have uploaded previously is the slot\_mapping method where I establish these relations between those entities and the required slots.

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

Also, as I previously said if I add the slot mappings at the _\_activate\_if\_required_ function the Form fill correclty the slots .

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

And here is the lines of code I added

```
            if latest_entities:
                
                """   
                       Extract the slot mappings and iterate over the entities and the mappings
                    for a given slot, at the moment just the type "from_entity" mappings are used
                """
                slot_mappings = self.get_mappings_for_slot(slot_name)
                for entity in latest_entities:
                    for slot_map in slot_mappings:
                        if slot_map['type'] == 'from_entity':
                            if slot_map['entity'] == entity['entity']:
                                prefilled_slots[slot_name] = entity['value']

```

With:

**latest\_entities = tracker.latest\_message.get(‘entities’, [])**

---

<div class="post-metadata">

**Author:** ![bvezilic](https://avatars.discourse-cdn.com/v4/letter/b/aeb1de/32.png) [@bvezilic](https://forum.rasa.com/u/bvezilic)\
**Post date:** [July 4, 2019, 11:39am UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/6 "2019-07-04T11:39:52Z")

</div>

Hi, I am having the exact same issue. It seems like ActionForm is not performing slot mapping on the message before its activation. To give an example, I used official RestaurantBot from examples which does mapping of entities with different names.

 ![rasa_slot_not_filling_marked](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/e/ec0759deae21a41ed2f0fb5ea720d29b885b1d31.png)

You can see what entities have been extracted (cuisine, num\_people, seating), however, only entities that have slots named the same are recorded. `seating` which should have been mapped to `outdoor_seating` is now requested to be filled, even though it was already provided.

Do you think this is intended behavior or it should be fixed?

---

<div class="post-metadata">

**Author:** ![erohmensing](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/erohmensing/32/1789_2.png) [@erohmensing](https://forum.rasa.com/u/erohmensing)\
**Post date:** [July 4, 2019, 12:41pm UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/7 "2019-07-04T12:41:48Z")

</div>

@cheloveco could you make a bug report on our github for this? I think you’re right. If you’re willing to tackle all of the slot mapping types, we’d also love to accept a contribution 🙂

---

<div class="post-metadata">

**Author:** ![stefandi94](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/stefandi94/32/3824_2.png) [@stefandi94](https://forum.rasa.com/u/stefandi94)\
**Post date:** [July 4, 2019, 2:19pm UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/8 "2019-07-04T14:19:22Z")

</div>

I have the same problem as @bvezilic 🙂

---

<div class="post-metadata">

**Author:** ![cheloveco](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@cheloveco](https://forum.rasa.com/u/cheloveco)\
**Post date:** [July 4, 2019, 3:51pm UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/9 "2019-07-04T15:51:21Z")

</div>

Sure I’ll do it, and I will be glad to contribute. 😃

---

<div class="post-metadata">

**Author:** ![erohmensing](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/erohmensing/32/1789_2.png) [@erohmensing](https://forum.rasa.com/u/erohmensing)\
**Post date:** [July 4, 2019, 3:53pm UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/10 "2019-07-04T15:53:59Z")

</div>

Awesome, thank you!

---

<div class="post-metadata">

**Author:** ![anurags](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/anurags/32/4500_2.png) [@anurags](https://forum.rasa.com/u/anurags)\
**Post date:** [July 8, 2019, 10:00am UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/11 "2019-07-08T10:00:35Z")

</div>

This is a problem I’ve faced as well and it is caused by this piece of code in rasa\_core\_sdk’s forms.py file. In the method `extract_other_slots()` of `class FormAction`,

```
# check whether the slot should be filled
# by entity with the same name
should_fill_slot = (other_slot_mapping["type"] == "from_entity" and
                             other_slot_mapping.get("entity") == slot and
                             self.intent_is_desired(other_slot_mapping, tracker)

```

Since this piece of code checks whether the slot name and entity name is the same, it blocks slots which aren’t named the same as the entity from being filled.

I have been wondering whether this was intentional or not and whether the code was written with a particular edge case in mind.

---

<div class="post-metadata">

**Author:** ![Egalite123](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/egalite123/32/780_2.png) [@Egalite123](https://forum.rasa.com/u/Egalite123)\
**Post date:** [November 21, 2019, 6:49pm UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/12 "2019-11-21T18:49:48Z")

</div>

Hi @cheloveco, Have been struggling with same issue. Can you pls share the rewritten function? I tried replicating this piece of code, but still running into problems.

Many thanks…

---

<div class="post-metadata">

**Author:** ![mengelhardt](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mengelhardt](https://forum.rasa.com/u/mengelhardt)\
**Post date:** [November 12, 2020, 7:18am UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/13 "2020-11-12T07:18:51Z")

</div>

Hi, as it seems to issue is not fixed until now RASA\_X\_VERSION=0.32.2 RASA\_VERSION=1.10.12 rasa-sdk:1.10.3

Will it be fixed sometime?

---

<div class="post-metadata">

**Author:** ![tinyapps](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/tinyapps/32/18201_2.png) [@tinyapps](https://forum.rasa.com/u/tinyapps)\
**Post date:** [November 24, 2021, 8:18am UTC](https://forum.rasa.com/t/are-slot-mappings-not-used-at-the-beginnig-of-a-form-action/12330/14 "2021-11-24T08:18:01Z")

</div>

Hello,

I am using RASA 2.8.8 and still have the issue? am I missing something?

Thanks!
