Failed to extract slot budget with action sales_form

Hello, I’m new to rasa,.Has anyone encountered this problem? I have been stuck on this issue for several days, please help me, thank you very much. As shown below, when I ask “why do you need to know that?”, I get an error “Failed to extract slot budget with action sales_form”. But everything goes well on the happy path,I don’t know why, I really need your help, please.

config.yml

# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: en
pipeline:
- name: "WhitespaceTokenizer"
- name: "RegexFeaturizer"
- name: "CRFEntityExtractor"
- name: "EntitySynonymMapper"
- name: "CountVectorsFeaturizer"
- name: "CountVectorsFeaturizer"
  analyzer: "char_wb"
  min_ngram: 1
  max_ngram: 4
- name: "EmbeddingIntentClassifier"
- name: "ResponseSelector"
# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
  - name: MemoizationPolicy
  - name: KerasPolicy
  - name: MappingPolicy
  - name: FormPolicy

domain.yml

actions:
- action_greet
- respond_faq
- utter_ask_budget
- utter_ask_business_email
- utter_ask_company
- utter_ask_job_function
- utter_ask_person_name
- utter_ask_use_case
- utter_cheer_up
- utter_did_that_help
- utter_explain_why_budget
- utter_explain_why_email
- utter_goodbye
- utter_greet
- utter_happy
- utter_iamabot
entities:
- budget
- business_email
- company
- job_function
- person_name
- use_case
forms:
- sales_form
intents:
- contact_sales
- inform
- explain
- greet:
    triggers: action_greet
- goodbye
- affirm
- deny
- mood_great
- mood_unhappy
- bot_challenge
- faq
responses:
  utter_ask_budget:
  - text: "What's your annual budget for conversational AI? "
  utter_ask_business_email:
  - text: What's your business email?
  utter_ask_company:
  - text: What company do you work for?
  utter_ask_job_function:
  - text: "What's your job? "
  utter_ask_person_name:
  - text: What's your name?
  utter_ask_use_case:
  - text: What's your use case?
  utter_cheer_up:
  - image: https://i.imgur.com/nGF1K8f.jpg
    text: 'Here is something to cheer you up:'
  utter_did_that_help:
  - text: Did that help you?
  utter_explain_why_budget:
  - text: We need to know your budget to recommend a subscription
  utter_explain_why_email:
  - text: We need your email so we can contact you
  utter_goodbye:
  - text: Bye
  utter_greet:
  - text: Hey! How are you?
  utter_happy:
  - text: Great, carry on!
  utter_iamabot:
  - text: I am a bot, powered by Rasa.
session_config:
  carry_over_slots_to_new_session: true
  session_expiration_time: 60
slots:
  budget:
    type: unfeaturized
  business_email:
    type: unfeaturized
  company:
    type: unfeaturized
  job_function:
    type: unfeaturized
  person_name:
    type: unfeaturized
  requested_slot:
    type: categorical
    values:
    - business_email
    - company
    - person_name
    - use_case
    - budget
    - job_function
  use_case:
    type: unfeaturized

nlu.md

## intent:greet
- hey
- hello
- hi
- good morning
- good evening
- hey there

## intent:goodbye
- bye
- goodbye
- see you around
- see you later

## intent:affirm
- yes
- indeed
- of course
- that sounds good
- correct

## intent:deny
- no
- never
- I don't think so
- don't like that
- no way
- not really

## intent:mood_great
- perfect
- very good
- great
- amazing
- wonderful
- I am feeling very good
- I am great
- I'm good

## intent:mood_unhappy
- sad
- very sad
- unhappy
- bad
- very bad
- awful
- terrible
- not very good
- extremely sad
- so sad

## intent:bot_challenge
- are you a bot?
- are you a human?
- am I talking to a bot?
- am I talking to a human?

## intent:faq/ask_channels
- What channels of communication does rasa support?
- what channels do you support?
- what chat channels does rasa uses
- channels supported by Rasa
- which messaging channels does rasa support?

## intent:faq/ask_languages
- what language does rasa support?
- which language do you support?
- which languages supports rasa
- can I use rasa also for another laguage?
- languages supported

## intent:faq/ask_rasax
- I want information about rasa x
- i want to learn more about Rasa X
- what is rasa x?
- Can you tell me about rasa x?
- Tell me about rasa x
- tell me what is rasa x

## intent:contact_sales
- I wanna talk to your sales people.
- I want to talk to your sales people
- I want to speak with sales
- Sales
- Please schedule a sales call
- Please connect me to someone from sales
- I want to get in touch with your sales guys
- I would like to talk to someone from your sales team
- sales please

## intent:inform
- [100k](budget)
- [240k/year](budget)
- [150,000 USD](budget)
- I work for [Rasa](company)
- The name of the company is [ACME](company)
- company: [Rasa Technologies](company)
- it's a small company from the US, the name is [Hooli](company)
- it's a tech company, [Rasa](company)
- [ACME](company)
- [Rasa Technologies](company)
- [maxmeier@firma.de](business_email)
- [bot-fan@bots.com](business_email)
- [my email is email@rasa.com](business_email)
- [engineer](job_function)
- [brand manager](job_function)
- [marketing](job_function)
- [sales manager](job_function)
- [growth manager](job_function)
- [CTO](job_function)
- [CEO](job_function)
- [COO](job_function)
- [John Doe](person_name)
- [Jane Doe](person_name)
- [Max Mustermann](person_name)
- [Max Meier](person_name)
- We plan to build a [sales bot](use_case) to increase our sales by 500%.
- we plan to build a [sales bot](use_case) to increase our revenue by 100%.
- a [insurance tool](use_case) that consults potential customers on the best life insurance to choose.
- we're building a [conversational assistant](use_case) for our employees to book meeting rooms.
- [brand manager](job_function)
- we plan to build a [sales bot](use_case) to increase our revenue by 100%.
- [240k/year](budget)
- [Jane Doe](person_name)
- [ACME](company)
- [my email is email@rasa.com](business_email)

## intent:explain
- why
- why is that
- why do you need it
- why do you need to know that?
- could you explain why you need it?

stories.md

## happy path
#* greet
#  - utter_greet
* mood_great
  - utter_happy

## sad path 1
#* greet
#  - utter_greet
* mood_unhappy
  - utter_cheer_up
  - utter_did_that_help
* affirm
  - utter_happy

## sad path 2
#* greet
#  - utter_greet
* mood_unhappy
  - utter_cheer_up
  - utter_did_that_help
* deny
  - utter_goodbye

## say goodbye
* goodbye
  - utter_goodbye

## bot challenge
* bot_challenge
  - utter_iamabot


## Some question from FAQ
* faq
    - respond_faq
    
## sales form
* contact_sales
    - sales_form
    - form{"name": "sales_form"}
    - form{"name": null}
    
## just sales, continue
* contact_sales
    - sales_form
    - form{"name": "sales_form"}
* faq
    - respond_faq
    - sales_form
    - form{"name": null}

## explain email
* contact_sales
    - sales_form
    - form{"name": "sales_form"}
    - slot{"requested_slot": "business_email"}
* explain
    - utter_explain_why_email
    - sales_form
    - form{"name": null}

## explain budget
* contact_sales
    - sales_form
    - form{"name": "sales_form"}
    - slot{"requested_slot": "budget"}
* explain
    - utter_explain_why_budget
    - sales_form
    - form{"name": null}

## interactive_story_1
* contact_sales
    - sales_form
    - form{"name": "sales_form"}
    - slot{"requested_slot": "job_function"}
* form: inform{"job_function": "brand manager"}
    - slot{"job_function": "brand manager"}
    - form: sales_form
    - slot{"job_function": "brand manager"}
    - slot{"requested_slot": "use_case"}
* form: inform{"use_case": "sales bot"}
    - slot{"use_case": "sales bot"}
    - form: sales_form
    - slot{"use_case": "we plan to build a sales bot to increase our revenue by 100%."}
    - slot{"requested_slot": "budget"}
* explain
    - utter_explain_why_budget
    - sales_form
    - slot{"requested_slot": "budget"}
* form: inform{"budget": "240k/year"}
    - slot{"budget": "240k/year"}
    - form: sales_form
    - slot{"budget": "240k/year"}
    - slot{"requested_slot": "person_name"}
* form: inform{"person_name": "Jane Doe"}
    - slot{"person_name": "Jane Doe"}
    - form: sales_form
    - slot{"person_name": "Jane Doe"}
    - slot{"requested_slot": "company"}
* form: inform{"company": "ACME"}
    - slot{"company": "ACME"}
    - form: sales_form
    - slot{"company": "ACME"}
    - slot{"requested_slot": "business_email"}
* form: inform{"business_email": "my email is email@rasa.com"}
    - slot{"business_email": "my email is email@rasa.com"}
    - form: sales_form
    - slot{"business_email": "my email is email@rasa.com"}
    - form{"name": null}
    - slot{"requested_slot": null}

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/core/actions/#custom-actions/


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

# from typing import Any, Text, Dict, List
#
# from rasa_sdk import Action, Tracker
# from rasa_sdk.executor import CollectingDispatcher
#
#
# class ActionHelloWorld(Action):
#
#     def name(self) -> Text:
#         return "action_hello_world"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#
#         dispatcher.utter_message(text="Hello World!")
#
#         return []

from typing import Dict, Text, Any, List, Union
from rasa_sdk.forms import FormAction
from rasa_sdk.events import UserUtteranceReverted
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher


class SalesForm(FormAction):
    """Collects sales information and adds it to the spreadsheet"""

    def name(self):
        return "sales_form"

    @staticmethod
    def required_slots(tracker):
        return [
            "job_function",
            "use_case",
            "budget",
            "person_name",
            "company",
            "business_email",
        ]

    def slot_mappings(self):
        # type: () -> 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 {"use_case": self.from_text(intent="inform")}

    def submit(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict]:
        dispatcher.utter_message("Thanks for getting in touch, we’ll contact you soon")
        return []


class ActionGreetUser(Action):
    """Revertible mapped action for utter_greet"""

    def name(self):
        return "action_greet"

    def run(self, dispatcher, tracker, domain):
        dispatcher.utter_message(template="utter_greet")
        return [UserUtteranceReverted()]

Hi @Chenmy111!

The error is coming because the bot failed to fill the slot budget with the user’s reply “why do you need to know that”.

It should not be a problem because the bot is behaving correctly in my opinion. Are you having any problem due to this error?

Hi, @saurabh-m523 ! I just want to know why the bot don’t follow my story

## explain budget
* contact_sales
    - sales_form
    - form{"name": "sales_form"}
    - slot{"requested_slot": "budget"}
* explain
    - utter_explain_why_budget
    - sales_form
    - form{"name": null}

when I said " *why do you need to know that", I want the bot to answer “utter_explain_why_budget” right away,the bot seems to execute “sales_form” before “utter_explain_why_budget”. This is what I don’t understand.

Ok, so the normal behavior of FormAction is to ask for the requested_slot and then validate it. In absence of any validation function, it simply checks if the slot is filled or not. Now this slot can only be filled by an extracted entity of the same name (unless you have mentioned how to fill this slot in the slot_mappings function.)

In your case, the FormAction is expecting to fill the requested slot budget (by asking “What’s your annual budget for conversational AI?”), but it couldn’t fill it because it couldn’t extract any entity of the name budget from the reply “why do you need to know that?”. At this point, the budget slot is empty, therefore any validation (simple or otherwise) for the slot budget will fail, hence you see the ERROR.

This ERROR allows other policies to decide the next action (in your case utter_explain_why_budget upon receiving the intent explain).

So I think you stories are getting followed correctly.

Hope that helps.

Thank you very much, I will try to add slot_mappings and validation function to those slots.Thanks for your help!