Form - How to fill only the requested slot?

Hi, I need to implement a use case where the bot collects 4 details from the user in the following order:

  1. claim_id - An alpha-numeric entry of length 1 to 50.
  2. first_name - a single word
  3. last_name - a single word
  4. npi - a 10-digit numeric entry

I am using a rasa form to implement this. But, when given input for the slot first_name, the last name is also getting filled. How to avoid this?

logs

2020-08-29 16:16:50 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'.
2020-08-29 16:16:50 DEBUG    rasa.core.lock_store  - Deleted lock for conversation '97bd019123d34337a9d5565bf41fb4ef'.
May I have your first name?
Your input ->  robin
2020-08-29 16:16:59 DEBUG    rasa.core.tracker_store  - Recreating tracker for id '97bd019123d34337a9d5565bf41fb4ef'
2020-08-29 16:16:59 DEBUG    rasa.core.processor  - Received user message 'robin' with intent '{'name': 'inform', 'confidence': 0.999647855758667}' and entities '[{'entity': 'name', 'start': 0, 'end': 5, 'value': 'robin', 'extractor': 'DIETClassifier'}]'
2020-08-29 16:16:59 DEBUG    rasa.core.processor  - Current slot values:
        claim_id: 85678f
        first_name: None
        last_name: None
        npi: None
        requested_slot: first_name
2020-08-29 16:16:59 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 25 events.
2020-08-29 16:16:59 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'prev_utter_can_do': 1.0, 'intent_claim_status_enquiry': 1.0}, {'intent_claim_status_enquiry': 1.0, 'prev_utter_details_message': 1.0}, {'prev_action_set_form_slots_null': 1.0, 'intent_claim_status_enquiry': 1.0}, {'intent_claim_status_enquiry': 1.0, 'active_form_claim_status_form': 1.0, 'prev_claim_status_form': 1.0}, {'entity_name': 1.0, 'prev_action_listen': 1.0, 'active_form_claim_status_form': 1.0, 'intent_inform': 1.0}]
2020-08-29 16:16:59 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
2020-08-29 16:16:59 DEBUG    rasa.core.policies.form_policy  - There is an active form 'claim_status_form'
2020-08-29 16:16:59 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_3_FormPolicy
2020-08-29 16:16:59 DEBUG    rasa.core.processor  - Predicted next action 'claim_status_form' with confidence 1.00.
2020-08-29 16:16:59 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'claim_status_form'.
2020-08-29 16:17:01 DEBUG    rasa.core.processor  - Action 'claim_status_form' ended with events '[BotUttered('Please enter NPI', {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, {"claim_id": "85678f", "first_name": "robin", "last_name": "robin", "requested_slot": "first_name"}, 1598698021.3448904), <rasa.core.events.SlotSet object at 0x00000162FBD37888>, <rasa.core.events.SlotSet object at 0x00000162FBD37848>, <rasa.core.events.SlotSet object at 0x00000162FBBECB48>]'.
2020-08-29 16:17:01 DEBUG    rasa.core.processor  - Current slot values:
        claim_id: 85678f
        first_name: robin
        last_name: robin
        npi: None
        requested_slot: npi
2020-08-29 16:17:01 DEBUG    rasa.core.policies.memoization  - Current tracker state [{}, {'prev_action_listen': 1.0, 'intent_claim_status_enquiry': 1.0}, {'prev_utter_can_do': 1.0, 'intent_claim_status_enquiry': 1.0}, {'intent_claim_status_enquiry': 1.0, 'prev_utter_details_message': 1.0}, {'prev_action_set_form_slots_null': 1.0, 'intent_claim_status_enquiry': 1.0}]
2020-08-29 16:17:01 DEBUG    rasa.core.policies.memoization  - There is a memorised next action 'claim_status_form'
2020-08-29 16:17:01 DEBUG    rasa.core.policies.mapping_policy  - There is no mapped action for the predicted intent, 'inform'.
2020-08-29 16:17:01 DEBUG    rasa.core.policies.form_policy  - There is an active form 'claim_status_form'
2020-08-29 16:17:01 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_3_FormPolicy
2020-08-29 16:17:01 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2020-08-29 16:17:01 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'.
2020-08-29 16:17:01 DEBUG    rasa.core.lock_store  - Deleted lock for conversation '97bd019123d34337a9d5565bf41fb4ef'.
Please enter NPI
Your input ->  /stop

nlu.md

## intent:inform
- [James](name)
- [Donette](name)
- ...
- [Lenna](name)
- [Mitsue](name)
- [ABC123](claim_id)
- [123XYZ](claim_id)
- ...
- [123456asdf](claim_id)
- [nKVb86W](claim_id)
- [0390749125](npi)
- [8557348396](npi)
- ...
- [2657580185](npi)
- [1405931347](npi)

## intent:claim_status_enquiry
- claim status
- my claim status
- claim status by ID
- claim status by claim id
- claim status inquiry
- status of a claim

stories.md

## claim_status 
* claim_status_enquiry
  - claim_status_form
  - form{"name": "claim_status_form"}
  - form{"name": null}
  - utter_slots_values

Domain.yml

intents:
  - inform
  - claim_status_enquiry

entities:
- claim_id
- name
- npi

slots:
  first_name:
    type: unfeaturized
    auto_fill: false
  last_name:
    type: unfeaturized
    auto_fill: false
  npi:
    type: unfeaturized
    auto_fill: false
  claim_id:
    type: unfeaturized
    auto_fill: false

responses:
  utter_slots_values:
  - text: "I am going to run a claim search using the following parameters:\n
          - Claim ID: {claim_id}\n
          - First Name: {first_name}\n
          - Last Name: {last_name}\n
          - NPI: {npi}\n"
  utter_ask_claim_id:
  - text: "Please enter the Claim ID you would like to know the status for."
  utter_ask_first_name:
  - text: "May I have your first name?"
  utter_ask_last_name:
  - text: "And your last name?"
  utter_ask_npi:
  - text: "Please enter NPI"

actions:
  - action_set_form_slots_null

forms:
  - claim_status_form

session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true

actions.py

class ClaimStatusForm(FormAction):
    def name(self) -> Text:
        return 'claim_status_form'

    @staticmethod
    def required_slots(tracker: Tracker) -> List[Text]:
        return ['claim_id', 'first_name', 'last_name', 'npi']

    def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
        """A dictionary to map required slots to
            - an extracted entity
            - intent: value pairs
            - a whole message
            or a list of them, where a first match will be picked"""

        return {
            "claim_id": [ 
                self.from_entity(entity="claim_id"),
                self.from_text(intent="inform"),
            ],
            "first_name": [
                self.from_entity(entity="name"),
                self.from_text(intent="inform"),
            ],
            "last_name": [
                self.from_entity(entity="name"),
                self.from_text(intent="inform"),
            ],
            "npi": [
                self.from_entity(entity="npi"),
                self.from_text(intent="inform"),
            ],
        }

    def submit(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List[Dict]:
  
        return []
1 Like

@Akhil I was stuck at the same issue…!! Got the solution here:

1 Like

Hi @KushwahaDK.

Thank you very much for the solution. But, I am getting errors in python code. I installed overrides using pip install overrides

This is the error

NameError: name 'EventType' is not defined

Were you able to run without errors using the same code snippet from the link you provided?

Solved it. I had to import them in actions.py file

from rasa_sdk.forms import FormAction, REQUESTED_SLOT
from rasa_sdk.events import SlotSet, EventType
1 Like

Great :slight_smile:

@KushwahaDK. Thank you very much for the help.