Custom Slot Mappings for Non-required Slots

Is it possible to create a custom slot mapping for slots that are not required by a form? More specifically, I have a form with 2 required slots and custom slot mappings for each of them (because the predefined mappings i.e. from_entity, from_intent, from_trigger_intent and from_text, do not fit my use-case). However, I also have other entities that I extract that are not required in order to respond to a query, but if the user does provide the information I would like to store it. These entities would also require a custom slot mapping.

The Rasa docs clearly state how to create a custom slot mapping for slots my form will request, but it is not clear how to create a custom slot mapping for any additional non-required slots.

Example:

I need two pieces of information in order to answer the question, domain and information_need. However, if the user provides a distance (e.g. 1000 meters), I would like to store that too, even though it’s not required to respond to the query. Below is an example of what my current code looks like in actions.py.

class ValidateTestForm(FormValidationAction):
    def name(self) -> Text:
        return "validate_test_form"

async def required_slots(
    self,
    slots_mapped_in_domain: List[Text],
    dispatcher: "CollectingDispatcher",
    tracker: "Tracker",
    domain: "DomainDict",
) -> Optional[List[Text]]:
 return ["domain", "information_need"]

async def extract_domain(
    self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
) -> Dict[Text, Any]:
#custom code to extract domain slot

async def extract_information_need(
    self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
) -> Dict[Text, Any]:
#custom code to extract information need slot

I am wondering where to put my custom extraction code for a third slot (distance) without having to make the slot required by the test form. Please let me know if I need to clarify any further.

2 Likes

Maybe you can define it as a slot in domain.yml and set auto_fill to true without defining it in the form.

slots:
  distance:
    type: float
    initial_value: null
    min_value: 0.0
    auto_fill: true
    influence_conversation: false

If you want to fill it only during the form, you can create another slot and fill that slot with the value distance slot using custom actions when the form is active. Don’t know if there’s a better way.

Thank you so much for your response!

I’m not sure that defining the slot in domain.yml and setting auto_fill to true will work because the slot needs a custom mapping.

I’m also not sure what you mean by “create another slot and fill that slot with the value distance slot using custom actions when the form is active.” Do you mind explaining this part a little more please?

1 Like

Oh sorry I don’t know about that then…

Lol yeah looking back I’m not sure what I meant either.

Create 2 slots, let’s say distance and distance_form. You set distance to auto fill whenever it finds a distance entity, and when your form is active, in the code of your FormValidationAction, you assign to distance_form the value of distance.

Hey any solution on this issue?

Not yet :slightly_frowning_face: