Can i reset slot X in custom validation of slot Y?

I have 2 slots, patient_name and confirm_patient_name, i have validation of slot confirm_patient_name if user input everthing except “ya”, will reset value of patient_name (not confirm_patient_name). how do i do this?

    def validate_confirm_patient_name(
        self,
        slot_value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict,
    ) -> Dict[Text, Any]:
        if slot_value == "ya":
            '''dispatcher.utter_message(text=f"user confirm YA")'''
            return {"confirm_patient_name":True}
        else:
            '''dispatcher.utter_message(text=f"user confirm TIDAK")'''

            return {"confirm_patient_name":None}

i changing return like this but its not work as expected, im totally lost here

return {"patient_name":None}

Hi @wiraadmaja could you please share your domain.yml file, to double-check your slots section as well as the slot mappings? Please confirm rasa version too.

thanks for reply! this is my domain.yml :

version: '2.0'
session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true

intents:
- greet
- affirm
- out_of_context
- goodbye
- deny
- give_name
- ask_status_vaccination

entities:
  - person_name

slots:
  patient_name:
    type: text
    influence_conversation: false
  confirm_patient_name:
    type: bool
    influence_conversation: false

forms:
  vaccination_form:
    required_slots:
      patient_name:
        - type: from_text

responses:
  utter_greet:
  - text: Halo! ada yang bisa saya bantu?
  utter_goodbye:
  - text: Sampai jumpa!
  utter_thanks:
  - text: Terima kasih!
  
actions:
- utter_greet
- utter_thanks
- utter_goodbye
- action_out_of_context
- action_ask_patient_name
- action_ask_confirm_patient_name
- action_complete_ask_vaccination_status
- validate_vaccination_form

here’s the version :

zotac@zotac:/home/wira$ rasa --ver
Rasa Version      :         2.8.3
Minimum Compatible Version: 2.8.0
Rasa SDK Version  :         2.8.1
Rasa X Version    :         0.42.0
Python Version    :         3.8.10
Operating System  :         Linux-5.4.0-90-generic-x86_64-with-glibc2.29
Python Path       :         /usr/bin/python3

Yes you can!

 return {"confirm_patient_name": None, "patient_name": None}

Look at this example:

async def validate_password(value, dispatcher, tracker, domain):
    if not tracker.get_slot('loggedin'):
        username = tracker.get_slot('username')
        password = value

        db = DatabaseConnection()
        count = db.query(f'SELECT COUNT(*) FROM user_info WHERE Username = {username} AND Password = {password}')

        if count == 1:
             dispatcher.utter_message(f'You are now logged in as {username}.')
            return {'password': 'secret', 'loggedin': True}
        else:
            dispatcher.utter_message(f'Sorry, you entered an incorrect password for {username}.')
            return {'password': None, 'loggedin': False}

    else: # Already logged in
        username = tracker.get_slot('username').title()
        dispatcher.utter_message(f'You are already logged in as {username}.')
        return {'username': username, 'password': 'secret', 'loggedin': True}

On top of that, I noticed this in your domain:

The form is not asking to fill confirm_patient_name, so validate_confirm_patient_name() shouldn’t even run.

I’m already tell the return with other slot is not works, also validate_confirm_patient_name is works, i just dont give you complete actions.py, here the full complete (and still cannot reset slot patient_name inside validate_confirm_patient_name

complete actions.py :

# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/custom-actions


# This is a simple example for a custom action which utters "Hello World!"

from typing import Any, Text, Dict, List, Optional
from rasa_sdk.events import SlotSet
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormValidationAction
from rasa_sdk.events import EventType
from rasa_sdk.types import DomainDict

class ActionOutOfContext(Action):
    def name(self) -> Text:
        return "action_out_of_context"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        dispatcher.utter_message(text="Maaf, maksudnya apa ya?")

        return []

class ActionCompleteAskVaccinationStatus(Action):
    def name(self) -> Text:
        return "action_complete_ask_vaccination_status"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        patient_name = tracker.get_slot('patient_name')
        dispatcher.utter_message(text=f"{patient_name}, anda sudah divaksinasi, terima kasih")
        return [SlotSet("patient_name",None)]

class AskForPatientName(Action):
    def name(self) -> Text:
        return "action_ask_patient_name"

    def run(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> List[EventType]:
        dispatcher.utter_message(text="Boleh tau nama lengkap anda? silakan ketik nama anda dibawah :")
        return []

class AskPatientNameConfirmation(Action):
    def name(self) -> Text:
        return "action_ask_confirm_patient_name"

    def run(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> List[EventType]:
        patient_name = tracker.get_slot('patient_name')
        dispatcher.utter_message(text=f"apakah benar nama anda adalah \"{patient_name}\"? ")
        return []

class ValidateVaccinationForm(FormValidationAction):
    def name(self) -> Text:
        return "validate_vaccination_form"

    async def required_slots(
        self,
        slots_mapped_in_domain: List[Text],
        dispatcher: "CollectingDispatcher",
        tracker: "Tracker",
        domain: "DomainDict",
    ) -> Optional[List[Text]]:
        additional_slots = ["confirm_patient_name"]
        if tracker.slots.get("patient_name") is not None:
            # jika nama pasien sudah terisi, konfirmasikan namanya bener apa nggak
            return additional_slots + slots_mapped_in_domain
        else:
            return slots_mapped_in_domain

    async def extract_confirm_patient_name(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> Dict[Text, Any]:
        user_input = tracker.latest_message.get("text")
        return {"confirm_patient_name": user_input}
       
    def validate_patient_name(
        self,
        slot_value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict,
    ) -> Dict[Text, Any]:
        if tracker.get_intent_of_latest_message() != "out_of_context":
            if len(slot_value) > 1:
                return {"patient_name":slot_value}
            else:
                dispatcher.utter_message(text=f"Maaf, nama: \"{slot_value}\" terlalu pendek, minimal 2 huruf")
                return {"patient_name":None}
        else:
            dispatcher.utter_message(text=f"Maaf, kami tidak mengerti maksud anda")
            return {"patient_name":None}

    def validate_confirm_patient_name(
        self,
        slot_value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict,
    ) -> Dict[Text, Any]:
        if slot_value == "ya":
            '''dispatcher.utter_message(text=f"user confirm YA")'''
            return {"confirm_patient_name":True}
        else:
            '''dispatcher.utter_message(text=f"user confirm TIDAK")'''

            return {"confirm_patient_name":None,"patient_name":None}

here the some debug :

Your input ->  n                                                                                                                           
2021-11-23 06:31:08 DEBUG    rasa.core.lock_store  - Issuing ticket for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:08 DEBUG    rasa.core.lock_store  - Acquiring lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:08 DEBUG    rasa.core.lock_store  - Acquired lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:08 DEBUG    rasa.core.tracker_store  - Recreating tracker for id 'e4a3c57b9f7041d988b0c6ac3c58ac0e'
2021-11-23 06:31:08 DEBUG    rasa.nlu.classifiers.diet_classifier  - There is no trained model for 'ResponseSelector': The component is either not trained or didn't receive enough training data.
2021-11-23 06:31:08 DEBUG    rasa.nlu.selectors.response_selector  - Adding following selector key to message property: default
2021-11-23 06:31:08 DEBUG    rasa.core.processor  - Received user message 'n' with intent '{'id': 6057978783892506229, 'name': 'affirm', 'confidence': 0.9353043437004089}' and entities '[]'
2021-11-23 06:31:08 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 61 events.
2021-11-23 06:31:08 DEBUG    rasa.core.policies.rule_policy  - Current tracker state:
[state 1] user intent: ask_status_vaccination | previous action name: action_listen
[state 2] user intent: ask_status_vaccination | previous action name: vaccination_form | active loop: {'name': 'vaccination_form'}
[state 3] user text: n | previous action name: action_listen | active loop: {'name': 'vaccination_form'}
2021-11-23 06:31:08 DEBUG    rasa.core.policies.rule_policy  - There is no applicable rule.
2021-11-23 06:31:08 DEBUG    rasa.core.policies.rule_policy  - Predicted loop 'vaccination_form'.
2021-11-23 06:31:08 DEBUG    rasa.core.policies.ensemble  - Made prediction using user intent.
2021-11-23 06:31:08 DEBUG    rasa.core.policies.ensemble  - Added `DefinePrevUserUtteredFeaturization(False)` event.
2021-11-23 06:31:08 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_0_RulePolicy.
2021-11-23 06:31:08 DEBUG    rasa.core.processor  - Predicted next action 'vaccination_form' with confidence 1.00.
2021-11-23 06:31:08 DEBUG    rasa.core.actions.forms  - Validating user input 'UserUttered(text: n, intent: affirm, use_text_for_featurization: False)'.
2021-11-23 06:31:08 DEBUG    rasa.core.actions.forms  - Trying to extract requested slot 'confirm_patient_name' ...
2021-11-23 06:31:08 DEBUG    rasa.core.actions.forms  - Got mapping '{'type': 'from_entity', 'entity': 'confirm_patient_name', 'intent': [], 'not_intent': [], 'role': None, 'group': None}'
2021-11-23 06:31:08 DEBUG    rasa.core.actions.forms  - Failed to extract requested slot 'confirm_patient_name'
2021-11-23 06:31:08 DEBUG    rasa.core.actions.forms  - Validating extracted slots: {}
2021-11-23 06:31:08 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'validate_vaccination_form'.
2021-11-23 06:31:08 DEBUG    rasa.core.actions.forms  - Request next slot 'confirm_patient_name'
2021-11-23 06:31:08 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'action_ask_confirm_patient_name'.
2021-11-23 06:31:08 DEBUG    rasa.core.processor  - Policy prediction ended with events '[<rasa.shared.core.events.DefinePrevUserUtteredFeaturization object at 0x7fdbce631580>]'.
2021-11-23 06:31:08 DEBUG    rasa.core.processor  - Action 'vaccination_form' ended with events '[<rasa.shared.core.events.SlotSet object at 0x7fdbce588460>, <rasa.shared.core.events.SlotSet object at 0x7fdbce60f7c0>, BotUttered('apakah benar nama anda adalah "Wira"? ', {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, {}, 1637649068.390572)]'.
2021-11-23 06:31:08 DEBUG    rasa.core.processor  - Current slot values: 
        patient_name: Wira
        confirm_patient_name: None
        requested_slot: confirm_patient_name
        session_started_metadata: None
2021-11-23 06:31:08 DEBUG    rasa.core.policies.rule_policy  - Predicted 'action_listen' after loop 'vaccination_form'.
2021-11-23 06:31:08 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_0_RulePolicy.
2021-11-23 06:31:08 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2021-11-23 06:31:08 DEBUG    rasa.core.processor  - Policy prediction ended with events '[]'.
2021-11-23 06:31:08 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'.
2021-11-23 06:31:08 DEBUG    rasa.core.lock_store  - Deleted lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
apakah benar nama anda adalah "Wira"?
Your input ->  n                                                                                                                           
2021-11-23 06:31:09 DEBUG    rasa.core.lock_store  - Issuing ticket for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:09 DEBUG    rasa.core.lock_store  - Acquiring lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:09 DEBUG    rasa.core.lock_store  - Acquired lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:09 DEBUG    rasa.core.tracker_store  - Recreating tracker for id 'e4a3c57b9f7041d988b0c6ac3c58ac0e'
2021-11-23 06:31:09 DEBUG    rasa.nlu.classifiers.diet_classifier  - There is no trained model for 'ResponseSelector': The component is either not trained or didn't receive enough training data.
2021-11-23 06:31:09 DEBUG    rasa.nlu.selectors.response_selector  - Adding following selector key to message property: default
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Received user message 'n' with intent '{'id': 6057978783892506229, 'name': 'affirm', 'confidence': 0.9353043437004089}' and entities '[]'
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 68 events.
2021-11-23 06:31:09 DEBUG    rasa.core.policies.rule_policy  - Current tracker state:
[state 1] user intent: ask_status_vaccination | previous action name: action_listen
[state 2] user intent: ask_status_vaccination | previous action name: vaccination_form | active loop: {'name': 'vaccination_form'}
[state 3] user text: n | previous action name: action_listen | active loop: {'name': 'vaccination_form'}
2021-11-23 06:31:09 DEBUG    rasa.core.policies.rule_policy  - There is no applicable rule.
2021-11-23 06:31:09 DEBUG    rasa.core.policies.rule_policy  - Predicted loop 'vaccination_form'.
2021-11-23 06:31:09 DEBUG    rasa.core.policies.ensemble  - Made prediction using user intent.
2021-11-23 06:31:09 DEBUG    rasa.core.policies.ensemble  - Added `DefinePrevUserUtteredFeaturization(False)` event.
2021-11-23 06:31:09 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_0_RulePolicy.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Predicted next action 'vaccination_form' with confidence 1.00.
2021-11-23 06:31:09 DEBUG    rasa.core.actions.forms  - Validating user input 'UserUttered(text: n, intent: affirm, use_text_for_featurization: False)'.
2021-11-23 06:31:09 DEBUG    rasa.core.actions.forms  - Trying to extract requested slot 'confirm_patient_name' ...
2021-11-23 06:31:09 DEBUG    rasa.core.actions.forms  - Got mapping '{'type': 'from_entity', 'entity': 'confirm_patient_name', 'intent': [], 'not_intent': [], 'role': None, 'group': None}'
2021-11-23 06:31:09 DEBUG    rasa.core.actions.forms  - Failed to extract requested slot 'confirm_patient_name'
2021-11-23 06:31:09 DEBUG    rasa.core.actions.forms  - Validating extracted slots: {}
2021-11-23 06:31:09 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'validate_vaccination_form'.
2021-11-23 06:31:09 DEBUG    rasa.core.actions.forms  - Request next slot 'confirm_patient_name'
2021-11-23 06:31:09 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'action_ask_confirm_patient_name'.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Policy prediction ended with events '[<rasa.shared.core.events.DefinePrevUserUtteredFeaturization object at 0x7fdbce4437f0>]'.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Action 'vaccination_form' ended with events '[<rasa.shared.core.events.SlotSet object at 0x7fdbce613520>, <rasa.shared.core.events.SlotSet object at 0x7fdbce460a90>, BotUttered('apakah benar nama anda adalah "Wira"? ', {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, {}, 1637649069.103176)]'.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Current slot values: 
        patient_name: Wira
        confirm_patient_name: None
        requested_slot: confirm_patient_name
        session_started_metadata: None
2021-11-23 06:31:09 DEBUG    rasa.core.policies.rule_policy  - Predicted 'action_listen' after loop 'vaccination_form'.
2021-11-23 06:31:09 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_0_RulePolicy.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Policy prediction ended with events '[]'.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'.
2021-11-23 06:31:09 DEBUG    rasa.core.lock_store  - Deleted lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
apakah benar nama anda adalah "Wira"?
Your input ->  n                                                                                                                           
2021-11-23 06:31:09 DEBUG    rasa.core.lock_store  - Issuing ticket for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:09 DEBUG    rasa.core.lock_store  - Acquiring lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:09 DEBUG    rasa.core.lock_store  - Acquired lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
2021-11-23 06:31:09 DEBUG    rasa.core.tracker_store  - Recreating tracker for id 'e4a3c57b9f7041d988b0c6ac3c58ac0e'
2021-11-23 06:31:09 DEBUG    rasa.nlu.classifiers.diet_classifier  - There is no trained model for 'ResponseSelector': The component is either not trained or didn't receive enough training data.
2021-11-23 06:31:09 DEBUG    rasa.nlu.selectors.response_selector  - Adding following selector key to message property: default
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Received user message 'n' with intent '{'id': 6057978783892506229, 'name': 'affirm', 'confidence': 0.9353043437004089}' and entities '[]'
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 75 events.
2021-11-23 06:31:09 DEBUG    rasa.core.policies.rule_policy  - Current tracker state:
[state 1] user intent: ask_status_vaccination | previous action name: action_listen
[state 2] user intent: ask_status_vaccination | previous action name: vaccination_form | active loop: {'name': 'vaccination_form'}
[state 3] user text: n | previous action name: action_listen | active loop: {'name': 'vaccination_form'}
2021-11-23 06:31:09 DEBUG    rasa.core.policies.rule_policy  - There is no applicable rule.
2021-11-23 06:31:09 DEBUG    rasa.core.policies.rule_policy  - Predicted loop 'vaccination_form'.
2021-11-23 06:31:09 DEBUG    rasa.core.policies.ensemble  - Made prediction using user intent.
2021-11-23 06:31:09 DEBUG    rasa.core.policies.ensemble  - Added `DefinePrevUserUtteredFeaturization(False)` event.
2021-11-23 06:31:09 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_0_RulePolicy.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Predicted next action 'vaccination_form' with confidence 1.00.
2021-11-23 06:31:09 DEBUG    rasa.core.actions.forms  - Validating user input 'UserUttered(text: n, intent: affirm, use_text_for_featurization: False)'.
2021-11-23 06:31:09 DEBUG    rasa.core.actions.forms  - Trying to extract requested slot 'confirm_patient_name' ...
2021-11-23 06:31:09 DEBUG    rasa.core.actions.forms  - Got mapping '{'type': 'from_entity', 'entity': 'confirm_patient_name', 'intent': [], 'not_intent': [], 'role': None, 'group': None}'
2021-11-23 06:31:09 DEBUG    rasa.core.actions.forms  - Failed to extract requested slot 'confirm_patient_name'
2021-11-23 06:31:09 DEBUG    rasa.core.actions.forms  - Validating extracted slots: {}
2021-11-23 06:31:09 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'validate_vaccination_form'.
2021-11-23 06:31:09 DEBUG    rasa.core.actions.forms  - Request next slot 'confirm_patient_name'
2021-11-23 06:31:09 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'action_ask_confirm_patient_name'.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Policy prediction ended with events '[<rasa.shared.core.events.DefinePrevUserUtteredFeaturization object at 0x7fdbce6312e0>]'.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Action 'vaccination_form' ended with events '[<rasa.shared.core.events.SlotSet object at 0x7fdbce33ad90>, <rasa.shared.core.events.SlotSet object at 0x7fdbce33ac10>, BotUttered('apakah benar nama anda adalah "Wira"? ', {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, {}, 1637649069.8484604)]'.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Current slot values: 
        patient_name: Wira
        confirm_patient_name: None
        requested_slot: confirm_patient_name
        session_started_metadata: None
2021-11-23 06:31:09 DEBUG    rasa.core.policies.rule_policy  - Predicted 'action_listen' after loop 'vaccination_form'.
2021-11-23 06:31:09 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_0_RulePolicy.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Policy prediction ended with events '[]'.
2021-11-23 06:31:09 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'.
2021-11-23 06:31:09 DEBUG    rasa.core.lock_store  - Deleted lock for conversation 'e4a3c57b9f7041d988b0c6ac3c58ac0e'.
apakah benar nama anda adalah "Wira"?
Your input -> 
return {"confirm_patient_name": None, "patient_name": None}

nope its also not work, its still not reset patient_name slot, also fyi my validate_confirm_patient_name is works, im using custom extract in actions.py, i tried to give the full code and full debug before but auto filter spam hide it

@wiraadmaja Is it correct to assume that confirm_patient_name is a dynamic slot you’re adding to the form only if patient_name is filled? According to the docs on dynamic form behaviour, you should have:

a) the extract_confirm_patient_name method in your FormValidationAction

b) override required_slots to include confirm_patient_name if patient_name is filled

Otherwise, it could be easier to add confirm_patient_name slot to form required_slots in the domain, with a from_intent slot mapping and use validate_confirm_patient_name method in your FormValidationAction.