How to prevent a slot from being overwritten?

Hey Everyone,

General description:

So, I have a FormAction asking for email address and a couple other slots, and when all are filled a custom action is executed. The first slot required is the email, and before any other slots are filled I run a validation against DB to check if user exists. If user exists, the email slot remains set and an additional VALID slot is filled as True. Then the form asks for the other things…

The problem is the following:

  • Let’s say the email gets validated and filled and so the VALID slot is True. Then the bot starts asking for other slots,
  • but the user for some reason enters a different email address as part of an intent E.g. “Can I do this with example@mail.com too?”, Then the email entity is recognized and the email slot gets filled with a new value.
  • Now this is not validated, but all other slots are already filled, or maybe the bot asks for one more and then the formaction is carried out.
  • This is a problem because the email is overwritten without the bot validating anything and the formaction is carried out with a wrong user or returns an error.

Therefore I would appreciate some help:

  1. Can I add somewhere that if the email slot is already filled, then it shouldn’t be filled again? If yes, where should I overwrite the FormAction class?
  2. Or maybe can I say that if a slot is already different than None, then it cannot be reset to anything but None?
  3. Any other ideas?

The following 2 topics are similar but not identical:

Hope this is clear, any ideas are appreciated.

2 Likes

I’d recommend to have different name for a slot and entity, this way the slot will not be automatically filled by FormAction. Otherwise you should override validate method and add overriding logic there

1 Like

How do you check if the user entred a valid email Adress first i hope you can help me

I’m getting the same issue.

I have a form with multiple questions which all use buttons and map from specific intentions, and a few of them use lookup tables, but the last question is a free-text response (intent mapped to None). If the free text is able to be matched with any phrase in any lookup table, it will override previous slots that rely on those lookup tables.

Example:

  • Slot A -> relies on intention/lookup table A
  • Slot B -> relies on intention B
  • Slot C -> relies on intention/lookup table C
  • Slot D -> free text (If any part of the free text matches something in lookup table A and/or lookup table C, Slots A and C will be overridden with the parts from the free-text that matched against lookup tables A and/or C)

I would like for the last free-text response to truly be free-text and not have any influence on previous slots.

I actually resolved this by creating a new slot that would hold the final value and is set upon validation

  • Example: at some point in the form I ask for a privacy_level value, which should either be “public” or “private”. If a person specifies “public”, then later in a free-response answer (that has nothing to do with the access state) they type in “private” as the free-response input it will override that privacy_level slot and bypass this validation function. The workaround is to set a new slot in the return with the final state, that way even if my privacy_level slot is overridden later, the slot with the final state is unaffected, and I can use this final state later on in my logic.

    def validate_privacy_level(
      self,
      value: Text,
      dispatcher: CollectingDispatcher,
      tracker: Tracker,
      domain: Dict[Text, Any]) -> Dict[Text, Any]:
      return {'privacy_level': value, 'final_privacy_level' : value}

Could you give some more insight as to how one can override the Validate method to prevent overwriting of slots?

Sorry, I’m not sure, I understand what do you mean

You can put your slot in none at the end of form, check SlockSet

you can do this

from rasa_sdk.events import SlotSet

put this where you can reset your slot

return [SlotSet(“your_slot_name”, None)]

In your earlier reply, you had suggested overriding the validate method and adding some logic there. So I am asking for more details on how I can do that…

Is there any method which checks if a slot is filled and if it is filled, not allow that value to be modified/ reset?

You need to put auto_fill: False in your slots declarition into domain file

example:

slots:

your_slot_name:

type: unfeaturized

auto_fill: False

@UlisesVD…what is the use of making auto_fill: False .?? and i want to override the slots if a new form is activated but it just takes pre-filled slots and validates it why is that?

@sohamcoder007 Could you please share your solution to this problem? I’m struggling with the same issue. Thank you so much