How to properly validate forms?

Hi all,
I am trying to validate a form containing six slots. Following this documentation, I have tried to validate one slot by:

actions:
- validate_standard_form

class ValidateStandardForm(FormValidationAction): 
def name(self) -> Text:
    return "validate_standard_form"
    
def validate_pizza_quantity(self,   
                            slot_value: Any,
                            dispatcher: CollectingDispatcher,
                            tracker: Tracker,
                            domain: DomainDict) -> Dict[Text, Any]:
    flag = 0
    for qty in slot_value:
        if qty < 1:
            flag = 1
            dispatcher.utter_message("!!!Pizza can't be negative!!!")
    if flag == 0:
        return {"pizza_quantity": slot_value}
    else:
        return {"pizza_quantity": None}

unfortunately, this function doesn’t work, so the slot can still be filled with negatives values, why?

In the link above, I have also read that we can use tracker.slots_to_validate() for customizing the validation, but I can’t figure out how. Were I could find more documentation/examples about it?

Just to check, could you share your domain.yml file? You may have misspelled a slot/form name. You don’t need to share the whole file, but the parts about entities, slots and forms might help us figure that out. Looking at the action code, it seems fine.

Note that you can also add print statements to the code to help you debug. You can confirm the slot value that goes into the action is actually received.

Thanks @koaning
Without the validation action, the form works fine.
I have tried to print a message at the beginning of the action, but it’s not displayed

 entities:
 - drink_type
 - drinks_quantity
 - hour
 - phone_number
 - pizza_quantity
 - pizza_type

slots:
  pizza_type:
    type: list
    influence_conversation: true
  drink_type:
    type: list
    influence_conversation: true
  pizza_quantity:
    type: list
    influence_conversation: false
  drinks_quantity:
    type: list
    influence_conversation: false
  hour:
    type: text
    influence_conversation: false
  phone_number:
    type: text
    influence_conversation: false

forms:
  standard_form:
    pizza_type:
    - type: from_entity
      entity: pizza_type
      intent: pizza_order
    drink_type:
    - type: from_entity
      entity: drink_type
      intent: drinks_order
    hour:
    - type: from_entity
      entity: hour
      intent: inform_hour
    phone_number:
    - type: from_entity
      entity: phone_number
      intent: inform_phone_number

I can’t help but notice that the pizza_quantity slot is not part of standard_form. Just to check, might that be causing your issue?

1 Like