Regarding Slots in Rasa 3.0

How to validate Slots using Forms in rasa 3.0?

domain.yml:

slots:
  first_name:
    type: text
    influence_conversation: false
    mappings:
    - type: custom
      
  last_name:
    type: text
    influence_conversation: false
    mappings:
    - type: custom

forms:
  personal_details_form:
    required_slots:
      - first_name
      - last_name


responses:
  utter_greet:
  - text: "Hey! How are you?"

  utter_ask_first_name:
  - text: "Please Enter Your *First Name*"

  utter_ask_last_name:
  - text: "Please Enter Your *Last Name*"
  
  utter_cheer_up:
  - text: "Here is something to cheer you up:"
    image: "https://i.imgur.com/nGF1K8f.jpg"

  utter_goodbye:
  - text: "Bye"

  utter_iamabot:
  - text: "I am a bot, powered by Rasa."

actions.py:

class ValidatePersonalInformation(FormValidationAction):
    def name(self) -> Text:
        return "validate_personal_details_form"

    def validate_first_name(
        self,
        slot_value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict
    )-> Dict[Text,Any]:
        print("First Name",slot_value)
        return {"first_name":slot_value} 
        # if len(first_name) <= 20:
        #     return {"first_name":slot_value,"invalid_form_count":None} 
        # else:
        #     return HelperServices.invalid_count_step_fun(tracker,dispatcher,"first_name")

    def validate_last_name(
        self,
        slot_value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict
    )-> Dict[Text,Any]:
        print("Last Name:",slot_value)
        return {"last_name":slot_value}
        # if len(last_name) <= 15:
        #     return {"last_name":slot_value,"invalid_form_count":None}
        # else:
        #     return HelperServices.invalid_count_step_fun(tracker,dispatcher,"email")

stories.py:

version: "3.0"

stories:

- story: Personal Details
  steps:
  - intent: greet
  - action: utter_greet
  - action: personal_details_form

What’s the problem you’re facing?

I => "Hi"
chatbot => "Please Enter Your *First Name*"
I => "Chittaranjan"
chatbot = > "Please Enter Your *First Name*"

and When I am giving the Chittaranjan as First Name to the chat bot that value is not stored in the slot first_name. So, Can I get help to resolve this issue. Actually I’m not getting actual solution in rasa 3.0 for this scenario.

Are there any errors appearing the the terminals of rasa shell and rasa run actions?

No

Please check this 2 screenshots

It not showing next utter message and previously provided value is not stored in request_slot:first_name

Can I get quick reply?

Please be patient, we are volunteers here.


Can you share your form activation story/rule? Or is there only the one you shared above?

I Kept Stories as it is.

Please activate the forms as per the docs.

1 Like

Here is 2 rule policy which one I should used

Delete lines 47+ since they’re just duplicates and uncomment the rest

ok

Still, I’m getting same issue

Can you show me your rules?

Yes

Hello @chittaranjanmore and welcome on forum! Can you confirm please this scenario:

I => "Hi"
chatbot => "Please Enter Your *First Name*"
I => "Chittaranjan"
chatbot = > "Your name is Chittaranjan"

That’s what you required as the response from the chatbot? Please update us.

Few observations and suggestions:

  1. I hope you mentioned the “validate_personal_details_form” under the actions in domain.yml
  2. hope you mentioned the utterance for the response you are expecting in domain.yml and same in stories.yml ?

For example as per demo use only:


  utter_slots_values:
  - text: I will remember that your name is {first_name} {last_name}!
- story: Personal Details
  steps:
  - intent: greet
  - action: utter_greet
  - action: personal_details_form
  - action: utter_slots_values

OR

Rules.yml

- rule: Submit form
  condition:
  - active_loop: personal_details_form
  steps:
  - action: personal_details_form
  - active_loop: null
  - slot_was_set:
    - requested_slot: null
  - action: utter_slots_values

For more details please ref this link: Forms OR See this Github Repo: https://github.com/RasaHQ/rasa-3.x-form-examples and example for validation.

Tip: Even try delete the older save models, if you think everything is fine and re-train the model again and run.

I hope this will help you to solve your issue.

You have not done that… Please read the whole docs and not the first two lines only.

- rule: Submit personal_details_form
  condition:
  - active_loop: personal_details_form
  steps:
  - action: personal_details_form
  - active_loop: null
  - slot_was_set:
    - requested_slot: null
  - action: action_submit_personal_details_form

ok

@chittaranjanmore is this issue persist for you or you were able to solve with the suggestion given my me or Chris?

1 Like