What's the right way to do form validation and getting slot value in custom action?

Hello, I’m working on rasa chatbot project that can diagnose you by giving percentage output based on the answer given by the user. Problem occurs when i run the program and it cannot fill form and save entity into slot like this

my goal is the custom action can extract the entity and use it to calculate percentage of the answers given. Most of the code that I write here are based from YouTube tutorials I’ve tried many ways that found online to fix it and I honestly didn’t know what am I doing wrong on this custom action. With that being said, any help will be much appreciated. Terminal debug and action server logs will be provided below the code.

  • Rasa & Rasa SDK: 2.7.0
  • Python: 3.8.5
  • OS: Windows 10
    import numpy as np
    from typing import Dict, Text, Any, List, Optional
    from rasa_sdk import Action, Tracker
    from rasa_sdk.executor import CollectingDispatcher
    from rasa_sdk.forms import FormAction, FormValidationAction
    from rasa_sdk.events import SlotSet, EventType
    from rasa_sdk.types import DomainDict
    class ValidateDiagnoseForm(Action):

        def name(self):

            return "diagnose_form"

        

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

            required_slots = ["nyerit", "nyeriot", "nyeris", "mual", "ruam"]

            

            for slot_name in required_slots:

                if tracker.slots.get(slot_name) is None:

                    #Slot is not filled yet. Request user to fill

                    return [SlotSet("requested_slot", slot_name)]

            #All slot are filled

            return [SlotSet("requested_slot", None)]

    class ValueDetails(Action):

        def name(self):

            return "value_details"

        

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

            #certainty factor user

            vnyerit=float(0.8)
            cfunt=vnyerit

            nyeriot=tracker.slots.get("nyeriot")
            vnyeriotEnt=next(tracker.get_latest_entity_values("nyeriot"), None)

            if vnyeriotEnt=="certain":
                cfuno=float(0.8)

            elif vnyeriotEnt=="uncertain":
                cfuno=float(0.4)

            else:
                cfuno=float(0)

            nyeris=tracker.slots.get("nyeris")
            vnyerisEnt=next(tracker.get_latest_entity_values("nyeris"), None)

            if vnyerisEnt=="certain":
                cfuns=float(0.8)

            elif vnyerisEnt=="uncertain":
                cfuns=float(0.4)

            else:
                cfuns=float(0)

            mual=tracker.slots.get("mual")
            vmualEnt=next(tracker.get_latest_entity_values("mual"), None)

            if vmualEnt=="certain":
                cfumu=float(0.8)

            elif vmualEnt=="uncertain":
                cfumu=float(0.4)

            else:
                cfumu=float(0)

            vruam=tracker.slots.get("ruam")
            vruamEnt=next(tracker.get_latest_entity_values("ruam"), None)

            if vruamEnt=="certain":
                cfuru=float(0.8)

            elif vruamEnt=="uncertain":
                cfuru=float(0.4)

            else:   
                cfuru=float(0)

            #certainty factor pakar

            cfpnt=float(1)
            cfpno=float(0.8)
            cfpns=float(1)
            cfpmu=float(0.4)
            cfpru=float(0.6)

            #menghitung nilai certainty factor

            cfnt=cfunt*cfpnt

            cfno=cfuno*cfpno

            cfns=cfuns*cfpns

            cfmu=cfumu*cfpmu

            cfru=cfuru*cfpru

            #kombinasi nilai cf dari masing-masing kaidah

            cfc12=cfnt+(cfno*(1-cfnt))

            cfc23=cfc12+(cfns*(1-cfc12))

            cfc34=cfc23+(cfmu*(1-cfc23))

            cfc45=cfc34+(cfru*(1-cfc23))

            diag=cfc45*100

            dispatcher.utter_message(text="Presentase Kepastian "+diag+" persen")

            if diag<50:

                dispatcher.utter_message(text="Dengan perhitungan gejala yang dialami, kamu tidak sakit DBD. Demam yang dialami dapat diobati secara mandiri.")

            elif diag>=50:

                

                dispatcher.utter_message(text="Dengan perhitungan gejala yang dialami, kamu sakit DBD. Tolong segera periksa ke Dokter terdekat.")

here is the logs text action server log.txt (1.2 KB) chatbot terminal debug log.txt (15.0 KB) Files that might help understanding my problem (it’s in Indonesian language) actions.py (3.9 KB) domain.yml (2.2 KB) rules.yml (656 Bytes) stories.yml (214 Bytes)

@dimdom21 Hi, please see these videos and implement your logic.

  1. https://youtu.be/CKn4ZBh9PpY 2.https://youtu.be/X255HJ_hAQ0

I hope it will solve you issue.

hi, thank you for your respond! :smile: i will give feedback after watching videos and fixing my code for the issues