How to set a slot inside a FormValidationAction?


I am trying to set a new slot new_slot if the user reply to one of Form queries to fill slot_1 was with intent `affirm. I have this but it does not work:

def validate_slot_1(
        slot_value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict,
    ) -> Dict[Text, Any]:
        if slot_value is True:
            return {"slot_new": True}
        elif slot_value is False:
            dispatcher.utter_message(response='test 2')
            return {"slot_new": False}
            dispatcher.utter_message(response='test 3')
            return {"slot_new": None}

How can I set a new slot using SlotSet() inside the validation functions?

You cannot use SlotSet() or events here.

What you’re doing should work.

  • Are you sure the action is executed? Try putting print() statements inside of it to check.
  • Is your slot called slot_1? The name of the method should be according to the slot’s name.
  • Try also validating the slot_1 slot. At least do return {"slot_new": True, "slot_1": slot_value} to return it as is

thanks @ChrisRahme for the help. When I set this slot_new it gets a value of true/false but it only lasts for that user response; after that, bot says new form query, and the slot_new appears as slot{“slot_new”:null}. How can I make sure the slot keeps its value until the end?

You must be setting the slot value somewhere else. Slots are supposed to be permanent.

Are you using Rasa Shell or Rasa X to talk to the bot? On Rasa X you can see every action, on Rasa Shell you should use --debug.

@ChrisRahme does that mean I cannot set a permanent slot inside a custom form validation action? It gets a value when user replies, but then automatically goes to ‘null’.

No. Slots do net get set to null unless you’re setting it to None somewhere else.

Use rasa shell --debug or Rasa X as suggested to see what’s actually happening to that slot.

@ChrisRahme thanks for your reply. I am using Rasa X and what I see as described: slot gets true/false value but in the next user response it automatically shows as slot{“slot_new”:null}. If you have any solution please let me know thanks

Weird. Please try seeing it on the shell

Was this solved? If yes, please mark the solution if it’s there already, or provide your own :slight_smile:

@userRasa03, I’m seeing the same issue. Did you find a way to solve this?