Insert slot value without return[SlotSet()]

Hi, I want to insert slot value without using return[SlotSet(' ',..)]. How can I do that between the code?

Is there something like tracker.set_slot()

1 Like

you should do it with returning events as you mentioned

yeah I know it is in good practice but for setting that slot value I have to create a new custom action which don’t have any other work except setting slot value. That’s why I am searching for new method to setting slot.

Resolved!!! tracker.slots[update_slot] = None

Checked with print slot is set but having an issue that it does not save slot in stories, stories have old slot values. Will try to resolve later.

It should be return [SlotSet(update_slot, None)]

@Ghostvv Yeah that’s the another and popular method but there are some people who need to fix the slots using tracker.slots[] method because they want to update slot in the middle of custom_action. I am trying to help those people.

P.S. Resolved my issue by using SlotSet method. Saw other posts so trying to help them.

I am trying to update the slots in the middle of custom_action, i have tried as you mentions above but i am facing the below error “TypeError: Object of type SlotSet is not JSON serializable” . Please help to resolve this issue. complete error as follows: on /webhook [POST] Traceback (most recent call last): File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\”, line 2292, in wsgi_app response = self.full_dispatch_request() File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\”, line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask_cors\”, line 161, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\”, line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\”, line 35, in reraise raise value File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\”, line 1813, in full_dispatch_request rv = self.dispatch_request() File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\”, line 1799, in dispatch_request return self.view_functionsrule.endpoint File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask_cors\”, line 128, in wrapped_function resp = make_response(f(*args, **kwargs)) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\rasa_core_sdk\”, line 91, in webhook return jsonify(response) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\”, line 321, in jsonify dumps(data, indent=indent, separators=separators) + ‘\n’, File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\”, line 179, in dumps rv = json.dumps(obj, **kwargs) File "C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\", line 399, in dumps **kw).encode(obj) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\simplejson\”, line 296, in encode chunks = self.iterencode(o, _one_shot=True) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\simplejson\”, line 378, in iterencode return iterencode(o, 0) File "C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\flask\", line 81, in default return _json.JSONEncoder.default(self, o) File “C:\ProgramData\Miniconda2\envs\advchatbot\lib\site-packages\simplejson\”, line 273, in default TypeError: Object of type SlotSet is not JSON serializable.

Please help me, Thanks in advance.

Can you send me your code line like what you typed?

Thank you for your response, when I am trying to update slots in middle of functions I got the above issue, now issue is resolved when I replace the return step as follows - return[SlotSet(’ ',…)]. Thank You.

1 Like

so, when you update tracker.slots, you change the local copy of tracker, that is passed to the custom action, in order to notify rasa_core that the slot has changed, you need to return SlotSet event


Yeah, Thanx @Ghostvv for clarifying it.


@abhishakskilrock need to store some information as slots which are not actually part of required_slots for my form. That’s why i was trying to update those slots using tracker.slots[‘slot_name’]=slot_value . I was doing it inside a slot validation method that needs to return the value of that particular slot. So, i can’t return anything but that slot inside that validation method. As you said i can see those slots being set just after using tracker.slots(). But if i call tracker.get_slot() for those slots from a different method than it shows that the slots were not set. How did you resolve this? P.S : i can’t return SlotSet() event as the validation method should only return the particular slot the validation method was created for. Here is my code:

def validate_bank_account_number(
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> Dict[Text, Any]:
        """Validate cuisine value."""
        if intent_found=="last_two_transaction":
            #raise ActionExecutionRejection(,f"Failed to extract slot with action {}",deactivate_form=True)
            #raise ActionExecutionRejection(,f"Failed to extract slot with action {}")
            #return self._deactivate()
        print("i am from bank account section and my value is ",value)
        if type(value)==str:
            if len(value.split())==13:
                 return {"bank_account_number": value}
        if type(value)!=list:
            return {"bank_account_number": None}
        if len(value)!=3:
            return {"bank_account_number": None}
            if len(value[0].split())!=13 and len(value[1].split())!=13 and len(value[2].split())!=13:
                return {"bank_account_number": None}
            for i in get_value.split():
                val_collection=list(show_df[show_df['Bank ID']==int(bank_id)].values[0])
                return {"bank_account_number": None}
            tracker.slots["temp_transaction"]= val_collection[5]
        return {"bank_account_number": bank_id}

@akelad can you suggest any shorts of workaround?

I know it’s a bit late, However, you can try something

return [SlotSet("temp_name", val_collection[3]),
        SlotSet(["temp_date_of_birth", val_collection[2]),
        SlotSet("temp_ballance", val_collection[4]),
        SlotSet("temp_transaction", val_collection[5]),
        SlotSet("bank_account_number", bank_id),

should work. try

Still looking for a way to set a slot without using return [SlotSet(slot_name, slot_value)] statement.

I am trying to set the slot from another slot’s validation method and hence I can’t use the return statement method

1 Like

Hello, I have the same problem, that is, I want to save the slot value without returning it. How do you finally solve this problem?

Looking forward to your reply, thank you very much!