How to prevent rasa filling slots which are not requesting

I have two slots named slot_a, slot_b for example, slot_a and slot_b is both from_intent type of slot mapping and can be filled by a same intent named intent_c. The problem is, when I am requesting slot_a and user trigger intent_c, slot_b is also filled. It is a confusing feature and it makes me hard to control the business logic. So anyone have a solution?

1 Like

At last, by reading the code, I fix it by change the code of rasa_sdk/form.py in the function extract_custom_slots:

for slot_name in slots_to_extract:
    extraction_output = await self._extract_slot(
        slot_name, dispatcher, tracker, domain
    )
    custom_slots.update(extraction_output)
    # for sequential consistency, also update tracker
    # to make changes visible to subsequent extract_{slot_name}
    tracker.slots.update(extraction_output)

will extract every custom slot whenever it is requesting. I changed it to:

for slot_name in slots_to_extract:
    # Add this line to prevent extract other slots.
    if slot_name != tracker.get_slot(REQUESTED_SLOT):
        continue
    extraction_output = await self._extract_slot(
        slot_name, dispatcher, tracker, domain
    )
    custom_slots.update(extraction_output)
    # for sequential consistency, also update tracker
    # to make changes visible to subsequent extract_{slot_name}
    tracker.slots.update(extraction_output)
2 Likes

Still dealing w/ this problem in Rasa 3.6.14, correct me if I’m wrong… Is there a way around this, without touching the package itself? Thank you.

Edit: this answer worked for me.