Is it possible to use intents (from nlu.yml) in slot validation?

Everything in the below code works fine. For validation I am using a small database. Whenever the user provides something out of database, the slot is set to none. As mentioned below in the output if the user says ‘yess’ instead of ‘yes’(which is in database), then the slot is set to none. I would like to know if there is a way to use intents (from nlu.yml) (in this case, user_affirm and user_deny) to perform slot validation, so that I don’t have to expect a perfect match from database everytime. It would also be okay if this can be achieved by any other method. Thanks


  • intent: user_affirm

    examples: |

    • yes
    • yesss
    • y
    • yeah
    • indeed
    • right
    • yup
    • correct
  • intent: user_deny

    examples: |

    • no
    • nooo
    • nope
    • nah
    • n
    • not




type: rasa.shared.core.slots.TextSlot
initial_value: null
auto_fill: true
influence_conversation: false



        - intent:
          - user_affirm
          - user_deny
        type: from_text

class Validate___(FVA):

def meal_options_db1() -> List[Text]:

    return ['yes', 'yeah', 'y', 'indeed', 'of course', 'that sounds good', 'right', 'yup', 'correct', ]

def meal_options_db2() -> List[Text]:

    return ['no', 'nope', 'nah', 'n', 'not', 'not so', 'never', 'don\'t think so', 'don\'t like that','no way', 
               'not really']

def validate_meal(
    slot_value: Text,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: DomainDict,
) -> Dict[Text, Any]:
    if slot_value.lower() in self.meal_options_db1():
        return {'meal': 'yes'}
    elif slot_value.lower() in self.meal_options_db2():
        return {'meal': 'no'}
    dispatcher.utter_message(text='can you repeat it?')
    return {'meal': None}

output 1

Bot: Did you have meal today?

User: yes

{‘meal’: ‘yes’}

output 2

Bot: Did you have meal today?

User: yess

{‘meal’: None}

You can read and parse the NLU from Custom Actions using the yaml module:

import yaml

with open("nlu.yml", "r") as nlu:
    except yaml.YAMLError as e:

To do the same for the domain, there is already a built-in way:

print(domain) # that's just it!