Form action validate() vs. validate_slotxyz()

I can’t find documentation for validate(), but I find it more general (and therefore more useful) than validate_slotxyz().

Is there danger in using validate() and is validate_slotxyz() just a convenience function?

The validate function does the following:

Extract and validate value of requested slot.

If nothing was extracted reject execution of the form action.
Subclass this method to add custom validation and rejection logic.

So, the validate function does not only validate the value that is set, but it also checks if the user may want to reject the form and break out from it. If the requested slot was filled, the validate function is calling the validate_slotxyz functions.

So, if you just want to update the validation of the set value, I would recommend to overwrite the validate_slotxyz function. If you want to add more/change the rejection logic, you should overwrite the validate function.

1 Like

Thanks @Tanja. That makes sense. I was wondering why rejections stopped working and now I know why!

@Tanja I’m still a little unclear about when validate vs validate_slotxyz is actually called. It seems that validate_slottxyz will only be called when slot_mappings() conditions are met. let’s say I have:

def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
    return {
        "slot1": self.from_entity(entity="entity_for_slot1", intent="inform"),
        "slot2": self.from_entity(entity="entity_for_slot2", intent="inform")

Let’s then say I am in the form for slot1 and then it extracts entity_for_slot1 entity, but let’s say it classifies the intent wrong. Since this mapping “fails”, it won’t call validate_slot1(). However, it will call validate().

If it actually matches the entity and the intent above, then it will call validate_slot1() and will not call validate().

That’s what seems to be happening. Can you confirm?

Yes, that is exactly what is happening.

1 Like