# Slot values being overwritten in Rasa

**URL:** <https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231>\
**Category:** Rasa Open Source\
**Created:** [October 5, 2021, 4:52pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231 "2021-10-05T16:52:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [October 5, 2021, 4:52pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/1 "2021-10-05T16:52:08Z")

</div>

I have two slots that are age and salary. The bot is getting confused and is overwriting these values

```auto
age:
      - entity: age_english
        type: from_entity
        not_intent: salary_english

 salary:
      - entity: salary
        type: from_entity
        not_intent: age_english

```

I have even tried not intents. Any help regarding this would be greatly appreciated

---

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [October 5, 2021, 10:29pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/2 "2021-10-05T22:29:46Z")

</div>

@kearnsw any idea on how this might work?

```auto
age:
    type: text
    influence_conversation: True
    auto_fill: False

```

I have set the auto\_fill to False and even then the slots are being overwritten

---

<div class="post-metadata">

**Author:** ![j.mosig](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/j.mosig/32/3588_2.png) [@j.mosig](https://forum.rasa.com/u/j.mosig)\
**Post date:** [October 6, 2021, 8:06am UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/3 "2021-10-06T08:06:06Z")

</div>

Hello @afnaan

What do you mean by “overwritten”? If entity extraction yields wrong results, you might need to provide more (or more realistic) training data.

---

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [October 6, 2021, 12:25pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/4 "2021-10-06T12:25:08Z")

</div>

hey @j.mosig what I mean when I am saying that the slots are being overwritten is that I have two numeric values in my form that is age and the salary. For both of these I have to just write their numerical values instead of giving values to bot like Age 30 salary 50000 So the bot confuses these values and overwrites the value of age in salary even though it has been filled before

---

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [October 6, 2021, 12:57pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/5 "2021-10-06T12:57:38Z")

</div>

![20211006_175458](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/a/f/af0847c6cb017b60063c6ea8c59e730a8b20ac1b.jpeg) ![20211006_175523](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/b/c/bc0b896301b047b3bf07ffc7f81b79eb166c8022.jpeg)You can see in these images that age is already stored in a slot but when I enter the salary it gets overwritten in the age slot@j.mosig

---

<div class="post-metadata">

**Author:** ![j.mosig](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/j.mosig/32/3588_2.png) [@j.mosig](https://forum.rasa.com/u/j.mosig)\
**Post date:** [October 7, 2021, 9:53am UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/6 "2021-10-07T09:53:05Z")

</div>

Ok, so because both age and salary are integers, both slots get mapped from the same entity. You can use a [form validation action](https://rasa.com/docs/rasa/forms#validating-form-input) to fix this. In your validation action, you can check that age is some number below 200 and salary something above 10000. You can also check what the requested slot is and make sure age only gets filled when age is requested. Does this help?

---

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [October 8, 2021, 10:35am UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/7 "2021-10-08T10:35:53Z")

</div>

@j.mosig I tried what you told me but the thing is I do not know we will write the story. I have edited the function for form validation action

```python
class ValidateAgeForm(FormValidationAction):
    
    def name(self) -> Text:
        return "user_age_form"

    @staticmethod
    def age() -> List[Text]:
       
        age = [age for age in range(19, 101)]
        print(age)
        return age

    def validate_cuisine(
        self,
        slot_value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict,
    ) -> Dict[Text, Any]:
        """Validate age value."""
        print('Age validated')
        if slot_value in self.age():
            
            return {"age": slot_value}
        else:
            # validation failed, set this slot to None so that the
            # user will be asked for the slot again
            return {"age": None}        

```

I think this function should verify that the age is between 18-100 but I don’t know how to write its story.

Also before the slot is validated it needs to has some input to be validated I guess? but as soon as I enter the salary the age slot gets overwritten.

---

<div class="post-metadata">

**Author:** ![j.mosig](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/j.mosig/32/3588_2.png) [@j.mosig](https://forum.rasa.com/u/j.mosig)\
**Post date:** [October 15, 2021, 10:40am UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/8 "2021-10-15T10:40:08Z")

</div>

```auto
def name(self) -> Text:
    return "user_age_form"

```

should be

```auto
def name(self) -> Text:
    return "validate_user_age_form"

```

if your form is called `user_age_form`.

---

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [October 15, 2021, 2:34pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/9 "2021-10-15T14:34:02Z")

</div>

@j.mosig so I have tried it and this works but the issue that I am now having is that when I enter salary even after validation it tries to overwrite the age but is unable to do so because of the validation check. so to validate other slots do we have to make a separate class or if we do it in the same class? what will be the process.

I have even tried slot mappings and still it is not working. Thank you so much for the help

```auto
class ValidateAgeForm(FormValidationAction):
    def name(self) -> Text:
        return "validate_user_details_form"
    
    def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
        return {
            "age": self.from_entity(entity="age", intent="age_english"),
            "salary": self.from_entity(entity="salary", intent="salary_english")
        }

    def validate_age(
        self,
        slot_value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict
    ) -> Dict[Text, Any]:
        if int(slot_value) >= 18 and int(slot_value) <= 100:
            print(slot_value)
            return {"age": slot_value}
        else:
            dispatcher.utter_message('Age must be between 18 and 100')
            return {"age": None}    

    def validate_salary(
        self,
        slot_value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict
    ) -> Dict[Text, Any]:
        print('Salary:', slot_value)
        if len(slot_value) >= 4 and len(slot_value) <= 7:
            print(slot_value)
            return {"salary": slot_value}
        else:
            dispatcher.utter_message('Salary must be between 1000 and 1000000')
            return {"salary": None}

```

---

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [October 15, 2021, 11:15pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/10 "2021-10-15T23:15:27Z")

</div>

@ChrisRahme do you have any idea how we might be able to do this?

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [October 16, 2021, 2:07pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/11 "2021-10-16T14:07:48Z")

</div>

Your validation seems fine.

> [@afnaan](#):
>
> when I enter salary even after validation it tries to overwrite the age but is unable to do so because of the validation check

What do you mean by that? What is happening?

> [@afnaan](#):
>
> so to validate other slots do we have to make a separate class or if we do it in the same class?

No, you write it in a same class same it is for a same action.

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [October 16, 2021, 2:14pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/12 "2021-10-16T14:14:05Z")

</div>

Maybe try mapping from text:

```python
class ValidateAgeForm(FormValidationAction):
    def name(self) -> Text:
        return "validate_user_details_form"
    
    def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
        return {
            "age": self.from_text(),
            "salary": self.from_text()
        }

    def validate_age(self, slot_value, dispatcher, tracker, domain) -> Dict[Text, Any]:
        try:
            slot_value = float(slot_value)
        except:
            dispatcher.utter_message('Age must be a number')
            return {"age": None} 

        if 18 <= slot_value <= 100:
            print(slot_value)
            return {"age": slot_value}
        else:
            dispatcher.utter_message('Age must be between 18 and 100')
            return {"age": None}    

    def validate_salary(self, slot_value, dispatcher, tracker, domain) -> Dict[Text, Any]:
        try:
            slot_value = float(slot_value)
        except:
            dispatcher.utter_message('Salary must be a number')
            return {"salary": None} 

        if 1000 <= slot_value <= 1000000:
            print(slot_value)
            return {"salary": slot_value}
        else:
            dispatcher.utter_message('Salary must be between 1000 and 1000000')
            return {"salary": None}
```

---

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [October 18, 2021, 6:24am UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/13 "2021-10-18T06:24:05Z")

</div>

No this does not resolves the issue. I mean by that is slot validation is working fine but when I write the salary it still overwrites the age slot. Now in the age slot there is a validation check and due to that it throws the exception that age must be between 18 & 100. The issue is still there that the bot is getting confused between age and salary as both the values are integers i.e age:18 salary:18000

---

<div class="post-metadata">

**Author:** ![j.mosig](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/j.mosig/32/3588_2.png) [@j.mosig](https://forum.rasa.com/u/j.mosig)\
**Post date:** [October 19, 2021, 8:02am UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/14 "2021-10-19T08:02:33Z")

</div>

To validate slot mappings of this kind, it’s probably best to just overwrite the `run` method:

```auto
class ValidateUserDetailsForm(Action):
    def name(self) -> Text:
        return "validate_user_details_form"

    def run(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> List[EventType]:
        print(f"slots_to_validate: {tracker.slots_to_validate()}")
        # ...

```

---

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [October 27, 2021, 1:23pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/15 "2021-10-27T13:23:05Z")

</div>

@j.mosig Can you please elaborate on how to overwrite the run method, I have written the following code but it is still overwriting the slots.

```nohighlight
    def name(self) -> Text:
        return "validate_balance_inquiry_form"
    def run(
          self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: DomainDict
      ) -> List[EventType]:

          slot_picked = tracker.slots_to_validate()
          validation_events = []
          try:
            slot_name = (list(slot_picked.keys())[0])
            slot_value = (list(slot_picked.values())[0])
            print(slot_name, slot_value, )
            if 6 < len(slot_value) < 15:
                validation_events.append(SlotSet("acc_num", slot_value))
            elif len(slot_value) <= 6:
                validation_events.append(SlotSet("otp", slot_value))
            else:
                validation_events.append(SlotSet(slot_name, slot_value))
          except Exception as e:
            print(e)
          

```

 ![Screenshot from 2021-10-27 18-21-15](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/7/7/772eb895517d830cfc1c406653a427c842d9f3c2.png)

 ![Screenshot from 2021-10-27 18-22-00](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/8/2/82ffc87a4840ba30659a3d26aee4f1457ff90e73.png)

PLEASE IGNORE THE LIST OUT OF INDEX ERROR. Thanks for your help. Regards

---

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [October 27, 2021, 10:18pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/16 "2021-10-27T22:18:25Z")

</div>

@ChrisRahme Can you help me figuring out how to do it?

---

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [November 1, 2021, 2:21pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/17 "2021-11-01T14:21:56Z")

</div>

@j.mosig can you please help me?

---

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [November 2, 2021, 12:07pm UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/18 "2021-11-02T12:07:10Z")

</div>

@nik202 can you help me on this?

---

<div class="post-metadata">

**Author:** ![afnaan](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@afnaan](https://forum.rasa.com/u/afnaan)\
**Post date:** [November 4, 2021, 10:30am UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/19 "2021-11-04T10:30:37Z")

</div>

@Juste I am having trouble with this. I am thinking of a new approach where I make an intent inform and get my otp and account no in the same intent. Will that somehow work?

---

<div class="post-metadata">

**Author:** ![j.mosig](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/j.mosig/32/3588_2.png) [@j.mosig](https://forum.rasa.com/u/j.mosig)\
**Post date:** [November 8, 2021, 11:36am UTC](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231/20 "2021-11-08T11:36:04Z")

</div>

@afnaan the `run` method has to return a list of events. Your function doesn’t return anything. You should have something like `return [SlotSet("acc_num", your_value)]` somewhere.

[Next page](https://forum.rasa.com/t/slot-values-being-overwritten-in-rasa/48231.md?page=2)
