How can I rerun or ask again a form?

So the user fills out a form and then I ask if the info es correct, if not, then the user inputs the id of the slot he/she wants to change. Then I change the corresponding slot value to None and consequently activate the form so it will ask the slot that is None only. The problem is that I am getting an error.

rasa-core_1               | 2021-09-27 17:23:03 ERROR    rasa.core.processor  - Encountered an exception while running action 'contractor_form'.Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.
rasa-core_1               | Traceback (most recent call last):
rasa-core_1               |   File "/opt/venv/lib/python3.7/site-packages/rasa/core/actions/action.py", line 671, in run
rasa-core_1               |     json=json_body, method="post", timeout=DEFAULT_REQUEST_TIMEOUT
rasa-core_1               |   File "/opt/venv/lib/python3.7/site-packages/rasa/utils/endpoints.py", line 155, in request
rasa-core_1               |     response.status, response.reason, await response.content.read()
rasa-core_1               | rasa.utils.endpoints.ClientResponseError: 500, Internal Server Error, body='b'<!DOCTYPE html><meta charset=UTF-8><title>500 \xe2\x80\x94 Internal Server Error</title><style>html { font-family: sans-serif }</style>\n<h1>\xe2\x9a\xa0\xef\xb8\x8f 500 \xe2\x80\x94 Internal Server Error</h1><p>The server encountered an internal error and cannot complete your request.\n''
rasa-core_1               | 
rasa-core_1               | The above exception was the direct cause of the following exception:
rasa-core_1               | 
rasa-core_1               | Traceback (most recent call last):
rasa-core_1               |   File "/opt/venv/lib/python3.7/site-packages/rasa/core/processor.py", line 751, in _run_action
rasa-core_1               |     output_channel, nlg, temporary_tracker, self.domain
rasa-core_1               |   File "/opt/venv/lib/python3.7/site-packages/rasa/core/actions/loops.py", line 26, in run
rasa-core_1               |     events += await self.activate(output_channel, nlg, tracker, domain)
rasa-core_1               |   File "/opt/venv/lib/python3.7/site-packages/rasa/core/actions/forms.py", line 669, in activate
rasa-core_1               |     prefilled_slots, tracker, domain, output_channel, nlg
rasa-core_1               |   File "/opt/venv/lib/python3.7/site-packages/rasa/core/actions/forms.py", line 403, in validate_slots
rasa-core_1               |     validate_events = await _action.run(output_channel, nlg, _tracker, domain)
rasa-core_1               |   File "/opt/venv/lib/python3.7/site-packages/rasa/core/actions/action.py", line 694, in run
rasa-core_1               |     raise RasaException("Failed to execute custom action.") from e
rasa-core_1               | rasa.shared.exceptions.RasaException: Failed to execute custom action.

Hello and welcome to the forum :slight_smile:

Can you please share the piece of code you think is the problem? Or share everything related to it.

Also, to properly share console output and code output, please use three backticks (```) before and after the code

```
like so
```

@ChrisRahme Thanks for the heads up

I have a form and also a validation action, I commented it out and now I can properly change the slot value and rerun the form. Is there any way I can achive this but keeping my validation?

1 Like
contractor_form:
    contractor_name:
      - type: from_text
    contractor_lastname:
      - type: from_text
    contractor_maidename:
      - type: from_text
    contractor_RFC:
      - type: from_text
    contractor_marital_status:
      - type: from_text
    contractor_phone_number:
      - type: from_text
    contractor_is_insured:
      - type: from_text
class ValidateContractorForm(FormValidationAction):
    def name(self) -> Text:
        return "validate_contractor_form"

    def validate_contractor_name(self, slot_value:Any, dispatcher:CollectingDispatcher, tracker:Tracker, domain:DomainDict) -> Dict[Text, Any]:
        if len(slot_value) <= 2:
            dispatcher.utter_message(text="Nombre bla bla, intente de nuevo.")
            return {"contractor_name":None}
        else:
            return {"contractor_name":slot_value}

    def validate_contractor_lastname(self, slot_value:Any, dispatcher:CollectingDispatcher, tracker:Tracker, domain:DomainDict) -> Dict[Text, Any]:
        if len(slot_value) <= 2:
            dispatcher.utter_message(text="Apellido paterno bla bla, intente de nuevo.")
            return {"contractor_lastname":None}
        else:
            return {"contractor_lastname":slot_value}

    def validate_contractor_maidename(self, slot_value:Any, dispatcher:CollectingDispatcher, tracker:Tracker, domain:DomainDict) -> Dict[Text, Any]:
        if len(slot_value) <= 2:
            dispatcher.utter_message(text="Apellido mateno bla bla, intente de nuevo.")
            return {"contractor_maidename":None}
        else:
            return {"contractor_maidename":slot_value} 

    def validate_contractor_RFC(self, slot_value:Any, dispatcher:CollectingDispatcher, tracker:Tracker, domain:DomainDict) -> Dict[Text, Any]:
        if len(slot_value) <= 2:
            dispatcher.utter_message(text="RFC no valido, intente de nuevo.")
            return {"contractor_RFC":None}
        else:
            return {"contractor_RFC":slot_value} 

    def validate_contractor_marital_status(self, slot_value:Any, dispatcher:CollectingDispatcher, tracker:Tracker, domain:DomainDict) -> Dict[Text, Any]:
        options = ["Casado", "Divorciado", "Soltero", "Unión Libre", "Viudo"]
        if  slot_value in ['1', '2', '3', '4', '5'] or slot_value in options:
            value = options[int(slot_value) - 1]
            return {"contractor_marital_status":value} 
        else:
            dispatcher.utter_message(text="Eliga un opción valida, intente de nuevo.")
            return {"contractor_marital_status":None}

    def validate_contractor_phone_number(self, slot_value:Any, dispatcher:CollectingDispatcher, tracker:Tracker, domain:DomainDict) -> Dict[Text, Any]:
        if len(slot_value) != 10:
            dispatcher.utter_message(text="Combinación de números no valida, intente de nuevo.")
            return {"contractor_phone_number":None}
        else:
            return {"contractor_phone_number":slot_value}   

    def validate_contractor_is_insured(self, slot_value:Any, dispatcher:CollectingDispatcher, tracker:Tracker, domain:DomainDict) -> Dict[Text, Any]:
        options = ["Si", "No"]
        if slot_value in ['1', '2'] or slot_value in options:
            value = options[int(slot_value) - 1]
            return {"contractor_is_insured":value}
        else:
            dispatcher.utter_message(text="Opción no valida, intente de nuevo.")
            return {"contractor_is_insured":None}
- story: path change contractor informacion
  steps:
  - checkpoint: filled_contractor_info
  - intent: select_number
    entities:
      - selected_num: "2"
  - slot_was_set:
      - selected_num: "2"
  - action: change_contractor_info_form
  - active_loop: change_contractor_info_form
  - active_loop: null
  - action: action_overrride_contractor_slots
  - action: contractor_form
  - active_loop: contractor_form
  - active_loop: null
  - action: utter_thanks

Thanks for formatting properly and even editing your first post :slight_smile:

It’s really weird that this works when you remove the validation… I see nothing wrong with your code.

This probably means there are more details in your custom actions log (the terminal in which you ran rasa run actions). Can you check if any errors are present there?

Thanks @ChrisRahme,

Rasa runs a validation before activating the form and there was an exception thrown at:

if slot_value in ['1', '2'] or slot_value in options:
            value = options[int(slot_value) - 1]
            return {"contractor_is_insured":value}

because “Si” was trying to be casted to int, my bad…

Thanks again!

1 Like

Oop haha :slight_smile: Glad you figured it out