Map a slot to free text or entity

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

  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!

Hello,

You can do exactly that with a FormValidationAction’s extract() method to get a custom slot mapping by writing some Python code :slight_smile:

Hello,

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

  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!

Can you show me what you did in the FormValidationAction?

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:

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

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.

1 Like

Thanks, it worked

1 Like