Getting this error "OverflowError: Maximum recursion level reached"

Rasa version: 1.9.3 python version: 3.7

I am using a form action to get some details from the user there are only 3 slots. So, right now what’s happing is first two slots are easily filed by asking questions to the user but when the answer of send slot comes to the action it sets the data to the slot but before asking the question for the next slot it show this error:

Exception occurred while handling uri: 'http://localhost:6008/webhook'
Traceback (most recent call last):
  File "C:\Users\shanu\.conda\botenv\lib\site-packages\sanic\app.py", line 976, in handle_request
    response = await response
  File "C:\Users\shanu\.conda\envs\botenv\lib\site-packages\rasa_sdk\endpoint.py", line 96, in webhook
    return response.json(result, status=200)
  File "C:\Users\shanu\.conda\envs\botenv\lib\site-packages\sanic\response.py", line 235, in json
    dumps(body, **kwargs),
OverflowError: Maximum recursion level reached

And this is my form action:

class ActionRegister(FormAction):

def __init__(self):
    self.valid = True
    self.ask_count = 0

def name(self) -> Text:
    """Unique identifier of the form"""
    return "action_register"

@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:
    """A list of required slots that the form has to fill"""
    return ["number", "name", "dob"]

def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:

    return {
        "number": [
            self.from_text()
        ],
        "name": [
            self.from_text()
        ],
        "dob": [
            self.from_text()
        ],
    }

def validate_number(
        self,
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
) -> Dict[Text, Any]:
    """Validates name"""
    # if isinstance(value, bytes):
    status, number = get_number_extracted(value)
    print(status, number)
    if status:
        self.ask_count = 0
        self.valid = True
        return {
            "number": number
        }
    else:
        self.ask_count += 1
        self.valid = False
        return {
            "number": None
        }

def validate_name(
        self,
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
) -> Dict[Text, Any]:
    """Validates name"""
    # if isinstance(value, bytes):
    name_status, name = get_name_extracted(value)
    print(name_status, name)
    if name_status:
        self.ask_count = 0
        self.valid = True
        print('valid')
        return {
            "name": name
        }
    else:
        self.ask_count += 1
        self.valid = False
        return {
            "name": None
        }

def validate_dob(
        self,
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
) -> Dict[Text, Any]:
    """Validates name"""
    # if isinstance(value, bytes):
    dob_status, dob = get_dob_extracted(value)
    if dob_status:
        self.ask_count = 0
        self.valid = True
        validation_status, message = get_details(tracker.get_slot('number'), tracker.get_slot('name'))
        if validation_status:
            return {
                "dob": dob
            }
        else:
            dispatcher.utter_message(text=message)
            return {
                "number": None,
                "name": None,
                "dob": None
            }
    else:
        self.ask_count += 1
        self.valid = False
        return {
            "number": None,
            "name": None,
            "dob": None
        }

def request_next_slot(
        self,
        dispatcher: "CollectingDispatcher",
        tracker: "Tracker",
        domain: Dict[Text, Any],
) -> Optional[List[EventType]]:
    for slot in self.required_slots(tracker):
        if self._should_request_slot(tracker, slot):
            if self.valid:
                template_name = "utter_ask_"
            else:
                template_name = "utter_ask_again_"
                self.valid = True
            dispatcher.utter_message(
                text=get_response_template(tracker.get_latest_input_channel(), f"{template_name}{slot}"))
            return [SlotSet(REQUESTED_SLOT, slot)]
        # no more required slots to fill
    return None

def submit(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
) -> List[Dict]:
    print("number: ", tracker.get_slot("number"))
    print("name: ", tracker.get_slot("name"))
    print("dob: ", tracker.get_slot("dob"))
    dispatcher.utter_message(text="Registration successful")
    return [AllSlotsReset()]

I can see that validation is done after slot has also been set and and utterence for the last slot is also passed but after that something happens my code throw this error. Please help!!! @j.mosig @akelad

1 Like

I’m with the same issue!

Hi, @shanushawanjha I met same issue but in different situation. The issue appear when I create a NLU component. Here is my approach to tackle:

The error due to sanic library. Sanic requires some constraints about type of variables. In more details, in return response.json(response_data) (in server.py in rasa), you should make sure response_data have suitable types. For example, in my case, response_data['intent']['confidence'] has type numpy.float32, so I converted it to python’s float and the issue is disappeared.

Hope this helps!

@liniribeiro you can see above approach

@duongkstn thank you your reply. I found the issue, actually I was sending an spacy doc object in response that why sanic library was showing the error.