Could any body tell me why the validation form methods don't be called automatically(don't work at all)?

could any body tell me why the validate_country and validate_pop_cap methods never be called automatically??? https://github.com/salama4ai/salama4ai-chatbot here is the action.py file content

# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/custom-actions


# This is a simple example for a custom action which utters "Hello World!"

from typing import Any, Text, Dict, List, Optional
from rasa_sdk import Action, Tracker, FormValidationAction
from rasa_sdk.events import SlotSet, EventType
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.types import DomainDict 
import requests
import json
#from aws_requests_auth.boto_utils import BotoAWSRequestsAuth
#import jwt

endpoint = "https://qcooc59re3.execute-api.us-east-1.amazonaws.com/dev/get"
timeout = 55

#auth = BotoAWSRequestsAuth(aws_host="qcooc59re3.execute-api.us-east-1.amazonaws.com",
#                           aws_region="us-east-1", aws_service="execute-api")


     #any class name but it's good to be as the name of the action in camel
class ValidateCountryPopCapForm(FormValidationAction):
    
    
    def name(self) -> Text:
        return "validate_country_pop_cap_form"
              #"validate_<form_name>"
                        
    
    #def validate_<slot_name>
    def validate_country(self, dispatcher: CollectingDispatcher, tracker: Tracker,
                         domain: DomainDict, slot_value: Any) -> Dict[Text, Any]:
        """ validate the 'country' value"""
        
        print("validate_country")  # to notify me when this function is called
        # check if the country slot value is not null
        if not slot_value:
            dispatcher.utter_message(response = "utter_ask_country")
            return {"country": None}              
            
        # check if the country slot value is in our database  in case the user give country
        country = slot_value.title()  
        print(country)
        try:
            res_country = requests.get(f"{endpoint}Countries", timeout=timeout)
            # check if the status_code is ok, less than 400 
            if not res_country.ok:
                raise Exception
            elif country not in res_country.json()["body"]:
                dispatcher.utter_message(response = "utter_not_found", country=country)
                return {"country": None}  
            else:
                print(country)
                return {"country", country}
        except:
            dispatcher.utter_message(response = "utter_server_failure")
            return {"country": None}

    #def validate_<slot_name>
    def validate_pop_cap(self, dispatcher: CollectingDispatcher, tracker: Tracker, 
                         domain: DomainDict, slot_value: Any) -> Dict[Text, Any]:
        """ validate the 'pop_cap' value"""
        
        print("validate_pop_cap")  # to notify me when this function is called
        try:
            pop_cap = slot_value.title()
            if (pop_cap in ["Capital", "Population"]):
                return {"pop_cap": pop_cap}
            else:
                raise Exception()
        except:
            dispatcher.utter_message(response = "utter_ask_pop_cap",
                                     buttons=[{"title": "Capital", 
                                              "payload": '/inform{"pop_cap":"Capital"}'},     
                                              {"title": "Population",
                                              "payload": '/inform{"pop_cap":"Population"}'}])
            return {"pop_cap": None}          
    
    
class ActionAnswer(Action):
    

    def name(self) -> Text:
        return "action_answer"

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

        country = tracker.get_slot("country")
        pop_cap = tracker.get_slot("pop_cap")              
        payload = {"country": country}
        #headers = {'Content-Type': 'application/json'}          
        print(pop_cap, country)
        # the action when the country is selected and pop_cap=capital        
        if pop_cap=="Capital":
            try:
                res_cap = requests.post(f"{endpoint}Capital", 
                                        json=payload, 
                                        timeout=timeout,
                                        #headers=headers, 
                                        #auth=auth
                                        )
                # check if the status_code is ok, i.e less than 400 
                # or i can not checking this it will raise an error any way
                if not res_cap.ok:
                    raise Exception             # res_cap.raise_for_status()
                # getting the response of capital
                cap = res_cap.json()["body"]["capital"]
                dispatcher.utter_message(response = "utter_answer_cap", 
                                         country = country, cap = cap)
            except:
                dispatcher.utter_message(response = "utter_server_failure")
                
                                        
        # the action when the country is selected and pop_cap=population
        elif pop_cap=="Population":
            try:
                res_pop = requests.post(f"{endpoint}Population", 
                                        json=payload, 
                                        timeout=timeout,
                                        #headers=headers, 
                                        #auth=auth
                                        )
                # check if the status_code is ok, i.e less than 400 
                if not res_pop.ok:
                    raise Exception
                # getting the response of population
                pop = res_pop.json()["body"]["population"]
                dispatcher.utter_message(response = "utter_answer_pop", 
                                         country = country, pop = pop)
            except:
                dispatcher.utter_message(response = "utter_server_failure")         
        return

Welcome to the forum!

Is your form called user_question?

Thank you Soo much

# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/custom-actions


# This is a simple example for a custom action which utters "Hello World!"

from typing import Any, Text, Dict, List, Optional
from rasa_sdk import Action, Tracker, FormValidationAction
from rasa_sdk.events import SlotSet, EventType
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.types import DomainDict 
import requests
import json
#from aws_requests_auth.boto_utils import BotoAWSRequestsAuth
#import jwt

endpoint = "https://qcooc59re3.execute-api.us-east-1.amazonaws.com/dev/get"
timeout = 55

#auth = BotoAWSRequestsAuth(aws_host="qcooc59re3.execute-api.us-east-1.amazonaws.com",
#                           aws_region="us-east-1", aws_service="execute-api")


     #any class name but it's good to be as the name of the action in camel
class ValidateCountryPopCapForm(FormValidationAction):
    
    
    def name(self) -> Text:
        return "validate_country_pop_cap_form"
              #"validate_<form_name>"
                        
    
    #def validate_<slot_name>
    def validate_country(self, dispatcher: CollectingDispatcher, tracker: Tracker,
                         domain: DomainDict, slot_value: Any) -> Dict[Text, Any]:
        """ validate the 'country' value"""
        
        print("validate_country")  # to notify me when this function is called
        # check if the country slot value is not null
        if not slot_value:
            dispatcher.utter_message(response = "utter_ask_country")
            return {"country": None}              
            
        # check if the country slot value is in our database  in case the user give country
        country = slot_value.title()  
        print(country)
        try:
            res_country = requests.get(f"{endpoint}Countries", timeout=timeout)
            # check if the status_code is ok, less than 400 
            if not res_country.ok:
                raise Exception
            elif country not in res_country.json()["body"]:
                dispatcher.utter_message(response = "utter_not_found", country=country)
                return {"country": None}  
            else:
                print(country)
                return {"country", country}
        except:
            dispatcher.utter_message(response = "utter_server_failure")
            return {"country": None}

    #def validate_<slot_name>
    def validate_pop_cap(self, dispatcher: CollectingDispatcher, tracker: Tracker, 
                         domain: DomainDict, slot_value: Any) -> Dict[Text, Any]:
        """ validate the 'pop_cap' value"""
        
        print("validate_pop_cap")  # to notify me when this function is called
        try:
            pop_cap = slot_value.title()
            if (pop_cap in ["Capital", "Population"]):
                return {"pop_cap": pop_cap}
            else:
                raise Exception()
        except:
            dispatcher.utter_message(response = "utter_ask_pop_cap",
                                     buttons=[{"title": "Capital", 
                                              "payload": '/inform{"pop_cap":"Capital"}'},     
                                              {"title": "Population",
                                              "payload": '/inform{"pop_cap":"Population"}'}])
            return {"pop_cap": None}          
    
    
class ActionAnswer(Action):
    

    def name(self) -> Text:
        return "action_answer"

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

        country = tracker.get_slot("country")
        pop_cap = tracker.get_slot("pop_cap")              
        payload = {"country": country}
        #headers = {'Content-Type': 'application/json'}          
        print(pop_cap, country)
        # the action when the country is selected and pop_cap=capital        
        if pop_cap=="Capital":
            try:
                res_cap = requests.post(f"{endpoint}Capital", 
                                        json=payload, 
                                        timeout=timeout,
                                        #headers=headers, 
                                        #auth=auth
                                        )
                # check if the status_code is ok, i.e less than 400 
                # or i can not checking this it will raise an error any way
                if not res_cap.ok:
                    raise Exception             # res_cap.raise_for_status()
                # getting the response of capital
                cap = res_cap.json()["body"]["capital"]
                dispatcher.utter_message(response = "utter_answer_cap", 
                                         country = country, cap = cap)
            except:
                dispatcher.utter_message(response = "utter_server_failure")
                
                                        
        # the action when the country is selected and pop_cap=population
        elif pop_cap=="Population":
            try:
                res_pop = requests.post(f"{endpoint}Population", 
                                        json=payload, 
                                        timeout=timeout,
                                        #headers=headers, 
                                        #auth=auth
                                        )
                # check if the status_code is ok, i.e less than 400 
                if not res_pop.ok:
                    raise Exception
                # getting the response of population
                pop = res_pop.json()["body"]["population"]
                dispatcher.utter_message(response = "utter_answer_pop", 
                                         country = country, pop = pop)
            except:
                dispatcher.utter_message(response = "utter_server_failure")         
        return

and these are from domain file

entities:
- country
- pop_cap

slots:
  pop_cap:
    type: categorical
    #initial_value: false    
    influence_conversation: false
    mappings:
    - type: from_entity
      entity: pop_cap
    values:
    - Capital
    - Population    
  country:
    type: text
    #initial_value: false    
    influence_conversation: false
    mappings:
    - type: from_entity
      entity: country      

forms:
  country_pop_cap_form:
    required_slots:
      - country
      - pop_cap
actions:
- utter_greet
- utter_offer
- utter_iamabot
- utter_thank
- utter_goodbye
- utter_ask_country
- utter_ask_pop_cap
- utter_not_found
- utter_server_failure
- utter_answer_cap
- utter_answer_pop
- utter_typo
- validate_country_pop_cap_form
- action_answer

is the name of my form, which contains 2 slots country and pop_cap

Please properly format code by enclosing it with 3 backticks (```) a line before a line after the code to make it more readable

```
like this
```

I’ve done it for you here 3 times by modifying your post but please do it yourself in the future :slight_smile:

Also please try to keep all the info in one reply instead of multiple sequential replies - If you want to edit a message you can click on the pencil button under it.


Do your print() statements inside the validate methods appear in the terminal in which you ran rasa run actions?

ok thank you for this note, yes i print to be able to see where is the program reach, and what is it’s actions

Yes I understand why you added print(), my question is whether or not you can see them in the terminal

yes the print results is appeared

ya ya i see them in the terminal

Okay so the methods are called automatically…

ok give me one minit of typing to explain exactly where i reached and recognized about the problem,

the print statements inside validation methods don’t appeared at all , but i called them explicitly inside the action_answer method , but that didn’t solve the problem, as the slots didn’t updated acordingly what i realized with high confidance that the valivation_<form_name> didn’t called automatically,

There is a problem here by the way.

To check if a variable is None, you use if x is None. To check if it is not None, you use if x is not None.

What you did here is if not x, which will get triggered if x is None, False, or 0.

Does the form even start or not?

ok great, what about the other issue of validation_<form_name>

no no didn’t start,

Show me your rules and stories please

i didn’t write any stories, but i write rule file