Validate categorical slot value in Stories and Custom Action

Hello, how do I check whether a value set to a slot has been specified in the domain? I want to know if this can be done in either the Stories file or during a Custom Action.

For example,

slots:
   account:
      type: categorical
      values:
      - a
      - b

Is it possible to do something like this in stories.md?

Story 1
* get_details{"account" != "a" and "account" != "b"}
  - utter_only_two_accounts_available

Or is it possible to do something in my Custom Action (action.py)?

if tracker.get_slot("account") not in <get_all_account_slot_possible_values>:
   #do something

I would prefer to avoid listing the values from my domain.yml in my action.py. Is there a method to get a list of specified values for a Categorical Slot?

2 Likes

I found out how to do the validation in my custom action. I can get the values of the slot using:

if tracker.get_slot('account') not in domain['slots']['account']['values']:
     #do something

But I still don’t know how to do this in stories.md. Is there a way to do so?

I feel you cannot directly do this in stories.

if you have an custom action - action_account_check like

if tracker.get_slot('account') not in domain['slots']['account']['values']:
       return [SlotSet("account_check","False")]

Then you can write your story something like

* my_intent
      - action_account_check
      - slot{"account_check":"False"}
      - utter_only_two_accounts_available

you can try out something like this. Story 1

  • get_details{“account” :null}
    • utter_only_two_accounts_available

i’m not sure if that is correct but it seems to be fork fine. also add other few stories like what happens if the value is set to ‘a’ and ‘b’

1 Like