TypeError: 'SlotSet' object is not subscriptable

Dear Team,

I am getting error as TypeError: ‘SlotSet’ object is not subscriptable when running rasa core interpreter with curstom action.

Error log:

ERROR:flask.app:Exception on /webhook [POST] Traceback (most recent call last): File “/home/ajontanu/jon/my_work/chatbot3/chatbot3/lib/python3.6/site-packages/flask/app.py”, line 2292, in wsgi_app response = self.full_dispatch_request() File “/home/ajontanu/jon/my_work/chatbot3/chatbot3/lib/python3.6/site-packages/flask/app.py”, line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File “/home/ajontanu/jon/my_work/chatbot3/chatbot3/lib/python3.6/site-packages/flask_cors/extension.py”, line 161, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File “/home/ajontanu/jon/my_work/chatbot3/chatbot3/lib/python3.6/site-packages/flask/app.py”, line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File “/home/ajontanu/jon/my_work/chatbot3/chatbot3/lib/python3.6/site-packages/flask/_compat.py”, line 35, in reraise raise value File “/home/ajontanu/jon/my_work/chatbot3/chatbot3/lib/python3.6/site-packages/flask/app.py”, line 1813, in full_dispatch_request rv = self.dispatch_request() File “/home/ajontanu/jon/my_work/chatbot3/chatbot3/lib/python3.6/site-packages/flask/app.py”, line 1799, in dispatch_request return self.view_functionsrule.endpoint File “/home/ajontanu/jon/my_work/chatbot3/chatbot3/lib/python3.6/site-packages/flask_cors/decorator.py”, line 128, in wrapped_function resp = make_response(f(*args, **kwargs)) File “/home/ajontanu/jon/my_work/chatbot3/chatbot3/lib/python3.6/site-packages/rasa_core_sdk/endpoint.py”, line 83, in webhook response = executor.run(action_call) File “/home/ajontanu/jon/my_work/chatbot3/chatbot3/lib/python3.6/site-packages/rasa_core_sdk/executor.py”, line 177, in run events = action(dispatcher, tracker, domain) File “/home/ajontanu/jon/my_work/chatbot3/chatbot3/lib/python3.6/site-packages/rasa_core_sdk/forms.py”, line 388, in run if e[‘event’] == ‘slot’: TypeError: ‘SlotSet’ object is not subscriptable

Custom Action file:

    def validate(self, dispatcher:CollectingDispatcher, tracker: Tracker,
             domain: Dict[Text, Any]) -> List[Dict]:

    "Validate extracted requested slot else raise an error"

    # extract slots that are not requested but set by corresponding entity
    slot_values = self.extract_other_slots(dispatcher, tracker, domain)

    #extract requested slot
    slot_to_fill = tracker.get_slot(REQUESTED_SLOT)

    if slot_to_fill:
        slot_values.update(self.extract_requested_slot(dispatcher, tracker, domain))

        if not slot_values:
            raise ActionExecutionRejection(self.name(),
                                           "Failed to validate slot {0}"
                                           "with action {1}"
                                           "".format(slot_to_fill, self.name))

    for slot, value in slot_values.items():
        if slot_values[slot] == 'gender':
            if value.lower() not in self.gender_db():
                dispatcher.utter_template('utter_wrong_gender', tracker)

                slot_values[slot] = None

    return [SlotSet(slot, value) for slot, value in slot_values.items()]

Hi @ajt,

First of all, I’m not sure what this form is doing, but is the line

if slot_values[slot] == 'gender':

supposed to be

if slot == 'gender':


As for the TypeError, can you show me your imports please? Is this the only custom code you have written?

This question was also asked here. So if you find the solution, give some updates in the issue TypeError: ‘SlotSet’ object is not subscriptable · Issue #1407 · RasaHQ/rasa_core · GitHub

which import for SlotSet do you use?