Validation from in actions.py

I am facing an issue for the form validation in rasa 2.0 . I went through the financial-bot but still I am not getting it. If someone could help me just with the basic form validation it would be great. Rasa Team please help. Thanks

@pitoulambert did you go through the documentation ?

Works perfectly fine for me.

how did you define the slots which does not have an entity in the form ?

slot_value: type: …

I’m sorry. I didn’t get your problem. Can you please elaborate more?

I want to validate cities and phone_number

In my nlu , there is an entity city_entry

- [Goa](city_entry)
- [Noida](city_entry)
- [Greater Noida](city_entry) 

In my domain

entities:

  • city_entry

slots:

city_entry:

type: text
influence_conversation: false
auto_fill: false

phone_number:

type: text
influence_conversation: false
auto_fill: false

forms:

property_form:

  city_entry:
    - type: from_entity
      entity: city_entry
      intent: request_service

  phone_number:
    - type: from_text

actions:

  • validate_property_commercial_form

session_config: session_expiration_time: 60 carry_over_slots_to_new_session: true

May I ask why you’ve kept the flag auto_fill as False?

The format of an action name for validation should be validate_{form_name}. So here it should be validate_property_form. Update the same in actions.py file as well.

Thanks for the format of the form action name

I put false because I don’t be to be filled automatically and randomly.

This is my actions file. it does not return the template I set for error

class ValidateCommercialPropertyForm(FormValidationAction):

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

@staticmethod
def city_entry_db() -> List[Text]:
    """Database of supported cities"""

    return ['Noida', 'Bangalore', 'Faridabad', 'Goa', 'Gurgaon', 'Kolkata', 'Mumbai', 'Pune', 'Agra', 'Lucknow',
      'Dehradun', 'Amritsar', 'Meerut', 'Patna', 'Greater Noida', 'Ghaziabad', 'New Delhi', 'Allahabad',
      'Ahmedabad', 'Bhopal', 'Bhubaneswar', 'Chandigarh', 'Chennai', 'Coimbatore', 'Hyderabad', 'Jaipur',
      'Mangaluru', 'Varanasi', 'Gwalior', 'Vadodara', 'Jalandhar', 'Jamshedpur', 'Kochi', 'Kozhikode',
      'Ludhiana', 'Mysore', 'Nagpur', 'Visakhapatnam', 'Raipur', 'Ranchi', 'Aurangabad', 'Surat', 'Indore',
      'Thiruvananthapuram',  'Saharanpur', 'Mohali', 'Bhiwadi', 'Rourkela']

def validate_city_entry(
    self,
    slot_value: Any,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: DomainDict,
) -> Dict[Text, Any]:
    """Validate cuisine value."""

    if slot_value.lower() in self.city_entry_db():
        return {"city_entry": slot_value}
    else:
        dispatcher.utter_message(template="utter_wrong_city_entry")
        return {"city_entry": None}

Kindly change validate_property_commercial_form to validate_property_form if the name of your form is property_form.

Thanks all , I figured out what’s wrong . I have just removed the entity in the nlu and apply the form validation as a slot with type from_text