# Map a slot to free text or entity

**URL:** <https://forum.rasa.com/t/map-a-slot-to-free-text-or-entity/49668>\
**Category:** Rasa Open Source\
**Created:** [December 1, 2021, 12:55pm UTC](https://forum.rasa.com/t/map-a-slot-to-free-text-or-entity/49668 "2021-12-01T12:55:46Z")\
**Posts on this page:** 7\
**Page:** 1

<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:** [December 1, 2021, 12:55pm UTC](https://forum.rasa.com/t/map-a-slot-to-free-text-or-entity/49668/1 "2021-12-01T12:55:46Z")

</div>

Hello,

the problem I have is as follow: I have a slot from\_account. In a form the user will be asked to provide an account to make the payment form. “Please tell me from which account you would like to make the payment”.

```auto
  tt_from_account:
    type: text
    influence_conversation: false
    mappings:
    - type: from_text
      conditions:
      - active_loop: tt_transfer_form
        requested_slot: tt_from_account

```

the user can answer in many ways:

“from my saving account” “from XXXX account” “saving” “1234”

in nlu data I can detect the account as entity if provided like “from my saving account” but if provided like “saving” there is no entity detected.

As it is now I always get the slot filled with the text ass user entered it.

Ideally I want a mapping that : if entity is detected, use it as slot value, if not use the text as it is.

Is it possible with custom slot type?

Thanks!

---

<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:** [December 1, 2021, 1:05pm UTC](https://forum.rasa.com/t/map-a-slot-to-free-text-or-entity/49668/2 "2021-12-01T13:05:35Z")

</div>

Hello,

> [@tinyapps](#):
>
> Ideally I want a mapping that : if entity is detected, use it as slot value, if not use the text as it is.
> 
> Is it possible with custom slot type?

You can do exactly that with a [FormValidationAction](https://rasa.com/docs/rasa/forms#advanced-usage)’s `extract()` method to get a [custom slot mapping](https://rasa.com/docs/rasa/forms#custom-slot-mappings) by writing some Python code 🙂

---

<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:** [December 1, 2021, 2:00pm UTC](https://forum.rasa.com/t/map-a-slot-to-free-text-or-entity/49668/3 "2021-12-01T14:00:43Z")

</div>

Hello,

I already tried the same but seems it is not working, or at least not the way I understand it.

```auto
  tt_amount:
    type: text
    influence_conversation: false
    mappings:
    - type: from_text
      conditions:
      - active_loop: tt_transfer_form
        requested_slot: tt_amount
  tt_from_account:
    type: text
    influence_conversation: false
    mappings:
    - type: custom
      action: action_hello_world

```

I have another slot right before this one, but the action gets called on the first slot/start of the from. Indeed the custom action is called on every slot instead of being called on when this slot is required?

Thanks again!

---

<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:** [December 1, 2021, 2:40pm UTC](https://forum.rasa.com/t/map-a-slot-to-free-text-or-entity/49668/4 "2021-12-01T14:40:14Z")

</div>

Can you show me what you did in the FormValidationAction?

---

<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:** [December 1, 2021, 3:01pm UTC](https://forum.rasa.com/t/map-a-slot-to-free-text-or-entity/49668/5 "2021-12-01T15:01:45Z")

</div>

I am using Action not FormValidationAction as I want only this slot to be custom.

So the action is called all the time and slot even gets overwritten.

Do you know when FormValidationAction is called (one every slot) and where I do declare it - in a custom slot?

Following the custom slot mapping docs:

```auto
slots:
  day_of_week:
    type: text
    mappings:
    - type: custom
      action: action_calculate_day_of_week

```

---

<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:** [December 1, 2021, 4:11pm UTC](https://forum.rasa.com/t/map-a-slot-to-free-text-or-entity/49668/6 "2021-12-01T16:11:23Z")

</div>

> [@tinyapps](#):
>
> I am using Action not FormValidationAction as I want only this slot to be custom.

Then you should use a FormValidationAction and implement its `extract()` method for this slot only. You don’t need to implement all methods for all slots.

---

<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:** [December 5, 2021, 6:32am UTC](https://forum.rasa.com/t/map-a-slot-to-free-text-or-entity/49668/7 "2021-12-05T06:32:48Z")

</div>

Thanks, it worked
