Is there a way to prevent the second slot validation in a form from executing until first slot is validated & completed.
Currently both my slots has some values which is wrong. During validation, both the slots are validated and uttering messages defined inside the respective slot validation which is not the right behavior.
How can we prevent this ? Kindly provide your suggestions.
If you implement it just like the docs, it is the default behavior. See the example below
class ValidateRestaurantForm(FormValidationAction):
def name(self) -> Text:
return "validate_restaurant_form"
@staticmethod
def cuisine_db() -> List[Text]:
"""Database of supported cuisines"""
return ["caribbean", "chinese", "french"]
def validate_cuisine(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate cuisine value."""
if slot_value.lower() in self.cuisine_db():
# validation succeeded, set the value of the "cuisine" slot to value
return {"cuisine": slot_value}
else:
# validation failed, set this slot to None so that the
# user will be asked for the slot again
return {"cuisine": None}
You have to return {“your_slot”: None} when the slot is not valid. Then the bot will automatically ask again for the same slot since it is not valid and will prevent from asking the next slot until the current one is ok.
Why don’t you validate against the database in the validate method? Just add your database logic in the slot validation method (according to your version). The “temp” values are passed as argument. It’s actually ideal that you do this in the validate method. If you don’t do this, it is inevitable that the bot will ask for the next slot. I am afraid you have to choose if you either want to validate everything together at the submit method or validate each one at a time.