Setting slots in custom action - error

I am trying to set a slot in a custom action. I have tried 4 different ways to set the slot and all of them result in an error message on the action server and a resulting crash of rasa interactive:

2022-06-27 21:10:39 ERROR    asyncio  - Task exception was never retrieved
future: <Task finished name='Task-9' coro=<SignalRouter._dispatch() done, defined at D:\Anaconda\envs\rasa4\lib\site-packages\sanic\signals.py:121> exception=ClientResponseError('500, Internal Server Error, body=\'b\'{"version":"3.1.0","status":"failure","message":"An unexpected error occurred. Error: \\\'list\\\' object has no attribute \\\'strip\\\'","reason":"ConversationError","details":{},"help":null,"code":500}\'\'')>

from actions.py: (The resulting error messages are included as comments)

class ActionValidateEmail(Action):
    def name(self) -> Text:
        return "action_validate_email"

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

            """"
            check if an email entity was extracted
            """
            entities = tracker.latest_message['entities']
            print(entities)
            dispatcher.utter_message(text=entities)
            for e in entities:
                if e.get("entity")== "email":
                    email = e.get("value")
                    print (f"Email was provided: {email}")
                
                else:
                    print("no email")
                    dispatcher.utter_message(response="utter_no_email")
                    return[SlotSet("email", None)]
                    #return [{"email": None}]

            """Validate email."""
            try: 
                # Validate & take the normalized form of the email
                # address for all logic beyond this point (especially
                # before going to a database query where equality
                # does not take into account normalization).

                val_email(email)
                print(f"try-statement: {email}")
                #return [SlotSet("email", email)]
                ## ERROR:
                # 2022-06-27 20:54:20 ERROR    rasa.server  - An unexpected error occurred. Error: 'list' object has no attribute 'strip'                
                #2022-06-27 20:54:20 ERROR    rasa.core.training.interactive  - failed to execute action!
                #2022-06-27 20:54:20 ERROR    rasa.core.training.interactive  - An exception occurred while recording messages.
                # 
                #return SlotSet("email", email)
                ### Error:
                # 2022-06-27 20:59:33 ERROR    rasa_sdk.executor  - Your action's 'action_validate_email' run method returned an invalid event. Event will be ignored.
                # 2022-06-27 20:59:33 ERROR    rasa_sdk.executor  - Your action's 'action_validate_email' run method returned an invalid event. Event will be ignored.
                # 2022-06-27 20:59:33 ERROR    rasa_sdk.executor  - Your action's 'action_validate_email' run method returned an invalid event. Event will be ignored.
                # 2022-06-27 20:59:33 ERROR    rasa_sdk.executor  - Your action's 'action_validate_email' run method returned an invalid event. Event will be ignored. 
                #  
                #return {"email": email}
                ### Error:
                # 2022-06-27 21:03:53 ERROR    rasa_sdk.executor  - Your action's 'action_validate_email' run method returned an invalid event. Event will be ignored.

                return [{"email": email}]
                ### Error:
                # 2022-06-27 21:10:39 ERROR    rasa_sdk.executor  - Your action 'action_validate_email' returned an action dict without the `event` property. Please use the helpers in `rasa_sdk.events`! Event willbe ignored!      

            except EmailNotValidError as e:
                # email is not valid, exception message is human-readable
                print(str(e))
                dispatcher.utter_message(response="utter_no_email")
                dispatcher.utter_message(text=str(e))
                dispatcher.utter_message(text= "Validate predefined slots")
                #return [{"email": None}]
                return[SlotSet("email", None)]

I am using: Rasa Version : 3.1.0 Minimum Compatible Version: 3.0.0 Rasa SDK Version : 3.1.1 Rasa X Version : None Python Version : 3.8.13 Operating System : Windows-10-10.0.19044-SP0 Python Path : D:\Anaconda\envs\rasa4\python.exe

Any suggestions how I can overcome this issue? Thanks a lot for your help!

@newinmunich

This one

return [{"email": email}]

doesn’t look right. Try replacing with

return [SlotSet("email", email)]

@siriusraja Thanks for your suggestion. I had already tried that.

I have finally found out that rasa crashed not due to the slot setting but due to the following code:

entities = tracker.latest_message['entities']
            print(entities)
            dispatcher.utter_message(text=entities)

I should have casted entities as a string before uttering it in the message. Fixing this issue solved the problem.