Rasa_sdk.endpoint - Failed to extract slot item with action issue_form

  • this is my action.py:*

from typing import Dict, Text, Any, List, Union, Optional

from rasa_sdk import Tracker from rasa_sdk.executor import CollectingDispatcher from rasa_sdk.forms import FormAction

class IssueForm(FormAction):

def name(self) -> Text:
    """Unique identifier of the form"""
    return "issue_form"

@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:
    """A list of required slots that the form has to fill"""
    return ['item','brand','part']

def validate_item(
    self,
    value: Text,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: Dict[Text, Any],
) -> Dict[Text, Any]:
    """Validate item"""
    if isinstance(value, str):
        if "mobile" in value:
            return {"item": value}
        elif "laptop" in value:
            return {"item": value}
        else:
            dispatcher.utter_message(template="utter_wrong_item")
            return {"item": None}
    else:
        return {"item": value}

@staticmethod
def brands_db() -> List[Text]:
    """Database of supported brands"""
    return [
        "lenovo",
        "asus",
        "apple",
        "sony",
        "vio",
        "dell",
        "toshiba",
        "hp",
        "msi",
        "asus",
        "apple",
        "sony",
        "xiomi",
        "realme",
        "oneplus",
        "lg",
        "oppo",
        "vivo",
        "acer",
    ]

@staticmethod
def parts_db() -> List[Text]:
    """Database of supported brands"""
    return [
        "display",
        "battery",
        "connectivity",
        "screen",
        "keyboard",
        "mouse",
        "performance",
    ]

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

    if value.lower() in self.brands_db():
        return {"brand": value}
    else:
        dispatcher.utter_message(template="utter_wrong_brand")
        return {"brand": None}

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

    if value.lower() in self.parts_db():
        return {"part": value}
    else:
        dispatcher.utter_message(template="utter_wrong_brand")
        return {"part": None}

def submit(self,
           dispatcher: CollectingDispatcher,
           tracker: Tracker,
           domain: Dict[Text, Any]
           ) -> List[Dict]:
    dispatcher.utter_message(template="utter_submit")
    return []

stories.md:

happy path1

  • greet
    • utter_greet
  • details_provider
    • issue_form
    • form{“name”: “issue_form”}
    • form{“name”: null}
    • utter_slots_values
  • goodbye
    • utter_goodbye

happy path2

  • greet
    • utter_greet
  • issue_provider
    • issue_form
    • form{“name”: “issue_form”}
    • form{“name”: null}
    • utter_slots_values
  • goodbye
    • utter_goodbye

happy path3

  • greet
    • issue_form
    • form{“name”: “issue_form”}
    • form{“name”: null}
    • utter_slots_values
  • goodbye
    • utter_goodbye

happy path4

  • issue_provider
    • issue_form
    • form{“name”: “issue_form”}
    • form{“name”: null}
    • utter_slots_values
  • goodbye
    • utter_goodbye

happy path5

  • details_provider

    • issue_form
    • form{“name”: “issue_form”}
    • form{“name”: null}
    • utter_slots_values
  • goodbye

    • utter_goodbye

    happy path6

  • issue_provider

    • issue_form
    • form{“name”: “issue_form”}
    • form{“name”: null}
    • utter_slots_values

config.yml:

Configuration for Rasa NLU.

Components

language: en

pipeline: supervised_embeddings

Configuration for Rasa Core.

Policies

policies:

  • name: MemoizationPolicy

  • name: KerasPolicy

  • name: MappingPolicy

  • name: FormPolicy

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:bot_challenge

  • are you a bot?

  • are you a human?

  • am I talking to a bot?

  • am I talking to a human?

intent:details_provider

intent:issue_provider

domain.yml:

intents:

  • greet
  • goodbye
  • affirm
  • deny
  • bot_challenge
  • details_provider
  • issue_provider

entities:

  • item
  • brand
  • part

slots: item: type: unfeaturized auto_fill: false brand: type: unfeaturized auto_fill: false part: type: unfeaturized auto_fill: false requested_slot: type: unfeaturized

templates: utter_ask_item:

  • text: “what’s your gadget?” utter_ask_brand:
  • text: “which brand?” utter_ask_part:
  • text: “which part?” utter_greet:
  • text: “Hey! How are you?” utter_did_that_help:
  • text: “Did that help you?” utter_goodbye:
  • text: “Bye” utter_iamabot:
  • text: “I am a bot, powered by Rasa.” utter_wrong_item:
  • text: “wrong item” utter_wrong_brand:
  • text: “wrong brand” utter_wrong_part:
  • text: “wrong part” utter_submit:
  • text: “submitted thanks” utter_slots_values:
  • text: “submitted your item: {item} of {brand}”

actions:

  • utter_greet
  • utter_did_that_help
  • utter_goodbye
  • utter_iamabot
  • utter_slots_values

forms:

  • issue_form

Now my issue is, 1.i train with rasa train, then talk using rasa run actions & rasa shell, Bot loaded. Type a message and press enter (use ‘/stop’ to exit): Your input -> some issues in my mobile
what’s your gadget? Your input -> some issues in my mobile
2020-01-03 16:10:09 ERROR rasa_sdk.endpoint - Failed to extract slot item with action issue_form 2020-01-03 16:10:09 ERROR rasa.core.actions.action - Failed to extract slot item with action issue_form

  1. after hello, I want sometimes bot ask about issue, sometimes it’ll greet me back, how can I do this?

HI there, It looks like you need to add a slot_mapping method to your actions.py class. Something like this should work

def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
        return {
            "item": self.from_text(intent=None),
            "brand": self.from_text(intent=None),
            "part": self.from_text(intent=None),
        }

the issue is fixed… I just removed this from domain requested_slot: type: unfeaturized and added slot mapping and restarted the laptop, finally issue is fixed… I Dont Know how…

That’s great news.

I’m pretty certain it was the missing slot_mapping function since that matches up values to your slots and the error you mention happens if that is missing.

Glad it is all working now. Welcome to the community :slight_smile:

1 Like