Forms
These docs are for version 1.x of Rasa Open Source.
User Guide
- Installation
- Rasa Tutorial
- Command Line Interface
- Architecture
- Messaging and Voice Channels
- Evaluating Models
- Validate Data
- Running the Server
- Running Rasa with Docker
- Cloud Storage
NLU
- About
- Using NLU Only
- Training Data Format
- Choosing a Pipeline
- Language Support
- Entity Extraction
- Components
Core
Conversation Design
API Reference
- Action Server
- HTTP API
- Jupyter Notebooks
- Agent
- Custom NLU Components
- Events
- Tracker
- Tracker Stores
- Event Brokers
- Training Data Importers
- Featurization
- Migration Guide
- Rasa Change Log
Reference
Forms
Note
There is an in-depth tutorial here about how to use Rasa Forms for slot filling.
Configuration File
To use forms, you also need to include the FormPolicy in your policy configuration file. For example:
policies:
- name: "FormPolicy"
Form Basics
Using a FormAction, you can describe all of the happy paths with a single story.
## happy path
* request_restaurant
- restaurant_form
- form{"name": "restaurant_form"}
- form{"name": null}
Custom slot mappings
If you do not define slot mappings, slots will be only filled by entities with the same name as the slot that are picked up from the user input.
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
return {
"cuisine": self.from_entity(entity="cuisine", not_intent="chitchat"),
"num_people": [
self.from_entity(entity="num_people", intent=["inform", "request_restaurant"]),
self.from_entity(entity="number"),
],
"outdoor_seating": [
self.from_entity(entity="seating"),
self.from_intent(intent="affirm", value=True),
self.from_intent(intent="deny", value=False),
],
"preferences": [
self.from_intent(intent="deny", value="no additional preferences"),
self.from_text(not_intent="affirm"),
],
"feedback": [self.from_entity(entity="feedback"), self.from_text()],
}
Validating user input
After extracting a slot value from user input, the form will try to validate the value of the slot.
def validate_cuisine(self, value: Text, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> Optional[Text]:
if value.lower() in self.cuisine_db():
return {"cuisine": value}
else:
dispatcher.utter_template("utter_wrong_cuisine", tracker)
return {"cuisine": None}
Handling unhappy paths
Typically, users will ask questions, make chitchat, change their mind, or otherwise stray from the happy path.
## chitchat
* request_restaurant
- restaurant_form
- form{"name": "restaurant_form"}
* chitchat
- utter_chitchat
- restaurant_form
- form{"name": null}
Handling conditional slot logic
Many forms require more logic than just requesting a list of fields.
@staticmethod
def required_slots(tracker) -> List[Text]:
if tracker.get_slot('cuisine') == 'greek':
return ["cuisine", "num_people", "outdoor_seating","preferences", "feedback"]
else:
return ["cuisine", "num_people","preferences", "feedback"]
Debugging
The first thing to try is to run your bot with the debug flag. If you are just getting started, you probably only have a few hand-written stories. This is a great starting point, but you should give your bot to people to test as soon as possible.