Forms
These docs are for version 1.x of Rasa Open Source.
User Guide
- Installation
- Tutorial: Rasa Basics
- Tutorial: Building Assistants
- Command Line Interface
- Architecture
- Messaging and Voice Channels
- Evaluating Models
- Validate Data
- Configuring the HTTP API
- Deploying your Rasa Assistant
- Cloud Storage
NLU
- About
- Using NLU Only
- Training Data Format
- Choosing a Pipeline
- Language Support
- Entity Extraction
- Components
Core
- About
- Stories
- Domains
- Responses
- Actions
- Policies
- Slots
- Forms
- Retrieval Actions
- Interactive Learning
- Fallback Actions
- Knowledge Base Actions
Conversation Design
API Reference
- Action Server
- HTTP API
- Jupyter Notebooks
- Agent
- Custom NLU Components
- Rasa SDK
- Events
- Tracker
- Tracker Stores
- Event Brokers
- Lock Stores
- Training Data Importers
- Featurization of Conversations
- Migration Guide
- Rasa OSS Change Log
Migrate from (beta)
Reference
Forms
Note
There is an in-depth tutorial here about how to use Rasa Forms for slot filling.
To use forms, you also need to include the FormPolicy in your policy configuration file. For example:
policies:
- name: "FormPolicy"
Using a FormAction, you can describe all of the happy paths with a single story. By "happy path", we mean that whenever you ask a user for some information, they respond with the information you asked for.
## happy path
* request_restaurant
- restaurant_form
- form{"name": "restaurant_form"}
- form{"name": null}
In this story the user intent is request_restaurant, which is followed by the form action restaurant_form.
The FormAction will only request slots which haven’t already been set. If a user starts the conversation with I’d like a vegetarian Chinese restaurant for 8 people, then they won’t be asked about the cuisine and num_people slots.
If you want to allow a combination of these, provide them as a list as in the example above.
After extracting a slot value from user input, the form will try to validate the value of the slot. Note that by default, validation only happens if the form action is executed immediately after user input.
def validate_cuisine(self, value: Text, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> Dict[Text, Any]:
"""Validate cuisine value."""
if value.lower() in self.cuisine_db():
return {"cuisine": value}
else:
dispatcher.utter_message(template="utter_wrong_cuisine")
return {"cuisine": None}
Of course your users will not always respond with the information you ask of them. The way this works with forms is that a form will raise an ActionExecutionRejection if the user didn’t provide the requested information.
The slot requested_slot is automatically added to the domain as an unfeaturized slot. If you want to make it featurized, you need to add it to your domain file as a categorical slot. You might want to handle your unhappy paths differently depending on what slot is currently being asked from the user.
Debugging
Try to run your bot with the debug flag, see Command Line Interface for details. If you are just getting started, you probably only have a few hand-written stories.
👋 I can help you get started with Rasa and answer your technical questions.