These docs are for version 1.x of Rasa Open Source.

---

# User Guide

- [Installation](https://legacy-docs-v1.rasa.com/1.10.1/user-guide/installation/)
- [Tutorial: Rasa Basics](https://legacy-docs-v1.rasa.com/1.10.1/user-guide/rasa-tutorial/)
- [Tutorial: Building Assistants](https://legacy-docs-v1.rasa.com/1.10.1/user-guide/building-assistants/)
- [Command Line Interface](https://legacy-docs-v1.rasa.com/1.10.1/user-guide/command-line-interface/)
- [Architecture](https://legacy-docs-v1.rasa.com/1.10.1/user-guide/architecture/)
- [Messaging and Voice Channels](https://legacy-docs-v1.rasa.com/1.10.1/user-guide/messaging-and-voice-channels/)
- [Testing Your Assistant](https://legacy-docs-v1.rasa.com/1.10.1/user-guide/testing-your-assistant/)
- [Setting up CI/CD](https://legacy-docs-v1.rasa.com/1.10.1/user-guide/setting-up-ci-cd/)
- [Validate Data](https://legacy-docs-v1.rasa.com/1.10.1/user-guide/validate-files/)
- [Configuring the HTTP API](https://legacy-docs-v1.rasa.com/1.10.1/user-guide/configuring-http-api/)
- [Deploying Your Rasa Assistant](https://legacy-docs-v1.rasa.com/1.10.1/user-guide/how-to-deploy/)
- [Cloud Storage](https://legacy-docs-v1.rasa.com/1.10.1/user-guide/cloud-storage/)

# Forms

Note
There is an in-depth tutorial [here](https://blog.rasa.com/building-contextual-assistants-with-rasa-formaction/) about how to use Rasa Forms for slot filling.

- [Configuration File](https://legacy-docs-v1.rasa.com/1.10.1/core/forms/#configuration-file)
- [Form Basics](https://legacy-docs-v1.rasa.com/1.10.1/core/forms/#form-basics)
- [Custom slot mappings](https://legacy-docs-v1.rasa.com/1.10.1/core/forms/#custom-slot-mappings)
- [Validating user input](https://legacy-docs-v1.rasa.com/1.10.1/core/forms/#validating-user-input)
- [Handling unhappy paths](https://legacy-docs-v1.rasa.com/1.10.1/core/forms/#handling-unhappy-paths)
- [The requested_slot slot](https://legacy-docs-v1.rasa.com/1.10.1/core/forms/#the-requested-slot-slot)
- [Handling conditional slot logic](https://legacy-docs-v1.rasa.com/1.10.1/core/forms/#handling-conditional-slot-logic)
- [Debugging](https://legacy-docs-v1.rasa.com/1.10.1/core/forms/#debugging)

One of the most common conversation patterns is to collect a few pieces of information from a user in order to do something (book a restaurant, call an API, search a database, etc.). This is also called **slot filling**.

If you need to collect multiple pieces of information in a row, we recommended that you create a `FormAction`. This is a single action which contains the logic to loop over the required slots and ask the user for this information.

## Configuration File
To use forms, you also need to include the `FormPolicy` in your policy configuration file. For example:

~~~yaml
policies:
  - name: "FormPolicy"
~~~

## Form Basics
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.

~~~yaml
## 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.

~~~python
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="number", intent=["inform", "request_restaurant"]
            ),
        ],
        "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. By default, validation checks if the requested slot was successfully extracted from the slot mappings.

~~~python
def validate_cuisine(self, value: Text, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> Dict[Text, Any]:
    if value.lower() in self.cuisine_db():
        return {"cuisine": value}
    else:
        dispatcher.utter_message(template="utter_wrong_cuisine")
        return {"cuisine": None}
~~~

## Handling unhappy paths
Of course your users will not always respond with the information you ask of them. Typically, users will ask questions or let the conversation stray from the happy path.

~~~yaml
## chitchat
* request_restaurant
    - restaurant_form
    - form{"name": "restaurant_form"}
* chitchat
    - utter_chitchat
    - restaurant_form
    - form{"name": null}
~~~

## Handling conditional slot logic
This mechanism is quite general and you can use it to build different kinds of logic into your forms.

~~~python
@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. Real user behavior will always surprise you!

👋 I can help you get started with Rasa and answer your technical questions.
