Prevent second slot validation in a form until first slot is completed - Getting Started with Rasa / Tutorials, Resources & Videos - Rasa Community Forum
Prevent second slot validation in a form until first slot is completed
Hi All,
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.
post by GeovanaRamos on May 24, 2021
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.
post by siriusraja on May 24, 2021
Thank you @GeovanaRamos for the response.
Is there way to tweak to this behavior as I need to retain some temp values in the slots and validate against the database one by one.
I am using rasa version 1.10.10 & rasa sdk 1.10.3
I tried this Custom action to ask next slot, but it doesn’t work. Not sure if this is available in my version.
post by ChikkaUdayaSai on May 24, 2021
Hi @siriusraja, The feature Custom action to ask in next slot in not available in 1.10.X
post by GeovanaRamos on May 24, 2021
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.