# How to extract entity in form only when user is asked for this entity

**URL:** https://forum.rasa.com/t/how-to-extract-entity-in-form-only-when-user-is-asked-for-this-entity/17108
**Category:** Rasa Open Source
**Created:** [September 23, 2019, 11:54am UTC](https://forum.rasa.com/t/how-to-extract-entity-in-form-only-when-user-is-asked-for-this-entity/17108 "2019-09-23T11:54:16Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![kaladin](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@kaladin](https://forum.rasa.com/u/kaladin)
#### Post date: [September 23, 2019, 11:54am UTC](https://forum.rasa.com/t/how-to-extract-entity-in-form-only-when-user-is-asked-for-this-entity/17108/1 "2019-09-23T11:54:16Z")

</div>

Hi, I want to create register form with 4 required slots

```
- first_name
- last_name
- email
- birth_date

```

For `first_name` and `last_name` I’m using custom slot mappings:

```
 def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
        return {
            "first_name": [self.from_text()],
            "last_name": [self.from_text()]
        }

```

And for email and birth\_date I’m using duckling extractor

My question is: how to prevent assigning birth\_date slot when user is asked for any other slot?

Example:

```
- Hey! How can I help you?
register
- Okay, I'll need you to provide me some information about yourself
- Give me your first name
January
- Give me your last name
Jefferson
- Give me your email
jf@aa.com
- first name: January
- last name: Jefferson
- email: jf@aa.com
- birth date: 2020-01-01
- Is this data correct?

```

As you can see duckling extracted date from provided first\_name (January) and didn’t even ask for it. Is there any way of limiting entity extraction in form so it’ll extract only entity that user is asked for?

---

<div class="post-metadata">

### Author: ![Tanja](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/tanja/32/4696_2.png) [@Tanja](https://forum.rasa.com/u/Tanja)
#### Post date: [September 24, 2019, 6:22am UTC](https://forum.rasa.com/t/how-to-extract-entity-in-form-only-when-user-is-asked-for-this-entity/17108/2 "2019-09-24T06:22:54Z")

</div>

Hi @kaladin, as far as I know that is not possible. The entity recognition/extraction is independent of the form. Rasa extracts whatever it detects and fills in the slots. However, you can maybe solve the problem using validation ([Forms](https://rasa.com/docs/rasa/core/forms/#validating-user-input)). In the validation method you have access to all slots and the user message. You could check what the value of the requested slot is, e.g. what question the bot just asked, and check if only that slot was newly set.

---

<div class="post-metadata">

### Author: ![Tarunkumar89](https://avatars.discourse-cdn.com/v4/letter/t/35a633/32.png) [@Tarunkumar89](https://forum.rasa.com/u/Tarunkumar89)
#### Post date: [September 24, 2019, 9:16am UTC](https://forum.rasa.com/t/how-to-extract-entity-in-form-only-when-user-is-asked-for-this-entity/17108/3 "2019-09-24T09:16:59Z")

</div>

Hi @Tanja , i am also facing same issue. if i have person\_name and company\_name entities ,sometime when i enter person\_name it takes it as company\_name as both are alphabets, how can we differentiate between these 2 . similarly i have campaign\_budget and campaign\_size and both are in numbers , here also when i enter 100000 it sets both the slots.

Please suggest.

---

<div class="post-metadata">

### Author: ![IgNoRaNt23](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ignorant23/32/8029_2.png) [@IgNoRaNt23](https://forum.rasa.com/u/IgNoRaNt23)
#### Post date: [September 24, 2019, 10:55am UTC](https://forum.rasa.com/t/how-to-extract-entity-in-form-only-when-user-is-asked-for-this-entity/17108/4 "2019-09-24T10:55:20Z")

</div>

Differentiating between name values is very very hard and requires lots of training data. The Spacy entity extractor got some pretrained models for names and companies. You might want to use these, if they fit to your language. For numbers, its pretty much impossible and you need to rely on the context as explained above.

---

<div class="post-metadata">

### Author: ![kaladin](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@kaladin](https://forum.rasa.com/u/kaladin)
#### Post date: [September 24, 2019, 11:46am UTC](https://forum.rasa.com/t/how-to-extract-entity-in-form-only-when-user-is-asked-for-this-entity/17108/5 "2019-09-24T11:46:37Z")

</div>

Thank you all for the replies. I solved this problem in the way sugested by @Tanja

Solution:

```
def validate_time(self, value, dispatcher, tracker, domain):
    requested_slot = tracker.current_state()['slots']['requested_slot']
   
    if requested_slot == 'time':
        return {"time": value}
    else:
        return {"time": tracker.get_slot('time')}
```

---

<div class="post-metadata">

### Author: ![Panka\_Patidar](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Panka\_Patidar](https://forum.rasa.com/u/Panka_Patidar)
#### Post date: [July 11, 2020, 11:49am UTC](https://forum.rasa.com/t/how-to-extract-entity-in-form-only-when-user-is-asked-for-this-entity/17108/6 "2020-07-11T11:49:26Z")

</div>

hello @kaladin , will you help me out with the first\_name and last\_name extraction , as you have shown above , i have tried the same but got the error { Failed to extract slot First\_name with action Register\_form } . Thank you
