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
ChrisRahme
(Chris Rahmé)
December 10, 2021, 6:29am
2
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.
ChrisRahme
(Chris Rahmé)
December 10, 2021, 6:42am
4
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
ChrisRahme
(Chris Rahmé)
December 10, 2021, 7:12am
8
chittaranjanmore:
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?
ChrisRahme
(Chris Rahmé)
December 10, 2021, 7:15am
10
Please activate the forms as per the docs.
1 Like
Here is 2 rule policy which one I should used
ChrisRahme
(Chris Rahmé)
December 10, 2021, 8:44am
12
Delete lines 47+ since they’re just duplicates and uncomment the rest
Still, I’m getting same issue
ChrisRahme
(Chris Rahmé)
December 10, 2021, 10:05am
15
Can you show me your rules?
nik202
(NiK202)
December 10, 2021, 4:19pm
17
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:
I hope you mentioned the “validate_personal_details_form
” under the actions in domain.yml
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.
ChrisRahme
(Chris Rahmé)
December 10, 2021, 4:33pm
18
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
nik202
(NiK202)
December 13, 2021, 11:20am
20
@chittaranjanmore is this issue persist for you or you were able to solve with the suggestion given my me or Chris?
1 Like