Checking slot value with database and give desired response

Hi i am a trying to understand the way FormAction and FormField works by modifying the restaurantbo example. I want to compare a slot’s value with database and ask the user to re-enter the value if it does not match with database

I am continuing from the prev forum discussion at

The custom FormField is as follows: I just used the code for EntityFormfield and modified the validate method

class MyFormField(FormField):

def __init__(self, entity_name, slot_name):
    self.entity_name = entity_name
    self.slot_name = slot_name

def validate(self, entity, value):
    if entity == 'cuisine':      
        if value not in cuis:
            value = None
    return value

def extract(self, tracker):
    # type: (Tracker) -> List[EventType]

    value = next(tracker.get_latest_entity_values(self.entity_name), None)
    validated = self.validate(self.entity_name,value)
    if validated is not None:
        return [SlotSet(self.slot_name, validated)]
        return [SlotSet(self.slot_name, None)]

class RestaurantForm(FormAction):

def required_fields():
    return [
        MyFormField("cuisine", "cuisine"),
        MyFormField("num_people", "num_people")          

def name(self):
    return 'restaurant_form'

def submit(self, dispatcher, tracker, domain):
    if cuis is None:
        dispatcher.utter_message('You did not enter the correct cuisine')
        return [UserUtteranceReverted()]

    dispatcher.utter_message("done! with "+str(n_people)+' '+cuis)  

I am able to set the slot value to None using the validate() As mentioned in Checking slot's value using database, i check the slot in action and send a utter_message and return UserUtteranceReverted

However if i enter the wrong cuisine the bot just keeps responding with utter_ask_cuisine instead of using the response that i want. Could someone please help me out

Hm I’m not sure it’s possible with the current version of forms, but we’re working on a new Forms v2 which is on a branch in rasa core that should be merged soon

Thanks for your reply. Can i use that branch of rasa-core? what branch of rasa_core_sdk should i use?

both are forms_v2 :slight_smile: there’s already some docs in the core branch too

thanks for your response…

I used the forms_v2 branch to do the trick. I have one additional query. If the cuisine and num_people are mentioned in one sentence… for example. “I want to book a restaurant with mexican cuisine for 3 people”

Its mentioned here also :Slot Filling The last bullet point under “Some important things to consider”

In that case , since both the slots are directly filled, the validate function of the form is not called… How to run validate the slots in this case?

Hi Aba ,

I am struggling with same issue. Could you please explain a bit how to use form v2 and where it is available currently.


you have to download and install the forms_v2 branch of rasa_core and rasa_core_sdk… in rasa_core there is an examples folder which has a folder called formbot…

Hi ABA ,

Thanks for reply. I tried using pip install git+ but no luck, when importing

from rasa_core_sdk.forms import REQUESTED_SLOT I am getting error REQUESTED_SLOT not found. Please let me know where i am doing wrong. Thanks again

did u do the same for rasa_core too? pip install git+

Yes I have same branch for rasa core

then it pretty much works out of the box

thank you for raising this question, it slipped out of our mind. We are working on adding such capability

1 Like

Dear Vladimir

thanks for considering my query. Is there some link where i can track this issue, so that i know that it is complete? Also would it be possible to add a functionality the value of the slot in the form is set with a yes/no question.

For example… utter_ask_num_people:

  • for how many people should the reservation be made.

The user enters 10. But the hotel has only 6 seats. So the bot replies with "Only 6 seats. Shall i go ahead with reservation for 6? If user says yes Then reservation is made for 6 ppl Else the user is asked to enter the num_people again


There are two open PRs:

To handle yes/no question, we added slot filling from intent: rasa_core_sdk/ at 33702f76322ad44b36ecc171362f4e661a6b0027 · RasaHQ/rasa_core_sdk · GitHub

Please take a look at outdoor_seating slot in formbot example: rasa_core/ at 7c53260aae3376ec1b7c5c927bae2b1c52110cfb · RasaHQ/rasa_core · GitHub

thank you vladimir. Will keep tracking the PRs

I checked the outdoor_seating slot. I think i did not get my point across properly. What i meant is following for one of slots in the form the following happens:

  1. … User enters an input
  2. … In the validate function that input is invalid
  3. . The bot looks up a value which is closer to the user entered value and suggests that as a possible solution
  4. . If user agrees to that then the value is retained , else user is asked to enter a new value all over again
  5. . If the user entered input in stage 1 was valid then the accept/deny is not triggered.

that is quite complicated custom logic that should go in validate method

I’ve just pushed extraction of extra slots

in the forms_v2 branch?