class ValidateNameForm(FormValidationAction):
def name(self) -> Text:
return "validate_name_form"
def validate_first_name(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate `first_name` value."""
# If the name is super short, it might be wrong.
print(f"First name given = {slot_value} length = {len(slot_value)}")
if len(slot_value) <= 2:
dispatcher.utter_message(text=f"That's a very short name. I'm assuming you mis-spelled. Can I ask your first name again?")
return {"first_name": None}
else:
return {"first_name": slot_value}
As you can see, I can ask in a different way if user input doesn’t fit the validation condition. However, we may get the repeating question from the orginal one - “What is your first name?”; as a result, a bot will say:
That’s a very short name. I’m assuming you mis-spelled. Can I ask your first name again? What is your first name?
Is there any way to let the bot say just the response from the validation action? Any help would be greatly appreciated. Thanks.
Good to see you, nik202! It’s related to action_loop things. If an input cannot meet the condition set from a validation action, we get a re-asking response from “utter_ask_[slot]” (What is your first name?) as well as the response from the validation (That’s a very short name. I’m assuming you mis-spelled. Can I ask your first name again?). I want to skip “utter_ask_[slot]” for the second turn.
@miner if the slot value is less then 2 then you returning the default message and if the slot_value is met then you returning the slot_value i.e the name.
Share me the rule or stories file, me still confused what you up to, apologises in advance.
No worries at all! Sorry for the unclear question.
slots:
first_name:
type: text
forms:
name_form:
first_name:
- type: from_text
responses:
utter_ask_first_name:
- text: What is your first name?
- story: test story
steps:
- intent: greet
- action: utter_greet
- intent: request_names
- action: name_form
- active_loop: name_form
- slot_was_set:
- requested_slot: first_name
- slot_was_set:
- requested_slot: null
- active_loop: null
With this setting, if a user say like:
user: hi
bot: good to meet you!
user: let me tell you my name
bot: What is your first name?
user: vh
bot: That’s a very short name. I’m assuming you mis-spelled. Can I ask your first name again?
bot: What is your first name? // want to stop this
@miner Right, then what is the significance of validating the input, this process is right, but you don’t want that it will asked the same question second time? i.e what is your first name, rather then your will again input the right value greater then 2 and it will display the first name right?
Yep. The point here is not about the validation condition as described here, though. Put it simple, I want to stop ‘utter_ask_first_name’ response for the validation turn.
user: hi
bot: good to meet you!
user: let me tell you my name
bot: What is your first name?
user: vh
bot: That’s a very short name. I’m assuming you mis-spelled. Can I ask your first name again?
bot: Ok.Thanks!
bot: I will remember thats your name is vh
If the user even mention the two string or
user: vh
bot: That’s a very short name. I’m assuming you mis-spelled. Can I ask your first name again?
user: nik
bot: Ok.Thanks!
bot: I will remember thats your name is nik
user: vh
bot: That’s a very short name. I’m assuming you mis-spelled. Can I ask your first name again?
user: nik
bot: Ok.Thanks!
bot: I will remember thats your name is nik