# Rasa 2.0, how are forms working?

**URL:** <https://forum.rasa.com/t/rasa-2-0-how-are-forms-working/35425>\
**Category:** Getting Started with Rasa\
**Created:** [October 3, 2020, 7:59pm UTC](https://forum.rasa.com/t/rasa-2-0-how-are-forms-working/35425 "2020-10-03T19:59:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![petasis](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@petasis](https://forum.rasa.com/u/petasis)\
**Post date:** [October 3, 2020, 7:59pm UTC](https://forum.rasa.com/t/rasa-2-0-how-are-forms-working/35425/1 "2020-10-03T19:59:54Z")

</div>

Hi all,

I am trying to port my bot from rasa 1.x to 2.x, but it has turned out a difficult process. The documentation is sparse, or I cannot understand it.

I have a form:

> ```
> forms:
> flight_departure_form:
> sl_frm_flight_departure_info_city:
> - type: from_entity
> entity: city
> intent:
> - flight_departure_info
> - inform
> 
> ```

And I am asking: “I am flying to Berlin”:

```
2020-10-03 22:51:07 DEBUG rasa.core.processor - Logged UserUtterance - tracker now has 10 events.
2020-10-03 22:51:07 DEBUG rasa.core.policies.memoization - Current tracker state [{}, {'user': {'intent': 'flight_departure_info', 'entities': ('flying', 'city', 'language')}, 'slots': {'language': (1.0, 0.0, 0.0)}, 'prev_action': {'action_name': 'action_listen'}}]
2020-10-03 22:51:07 DEBUG rasa.core.policies.memoization - There is no memorised next action
2020-10-03 22:51:07 DEBUG rasa.core.policies.rule_policy - Current tracker state: [{}, {'user': {'intent': 'flight_departure_info', 'entities': ('flying', 'city', 'language')}, 'slots': {'language': (1.0, 0.0, 0.0)}, 'prev_action': {'action_name': 'action_listen'}}]
2020-10-03 22:51:07 DEBUG rasa.core.policies.rule_policy - There is a rule for the next action 'flight_departure_form'.
2020-10-03 22:51:07 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_2_RulePolicy
2020-10-03 22:51:07 DEBUG rasa.core.processor - Predicted next action 'flight_departure_form' with confidence 1.00.
2020-10-03 22:51:07 DEBUG rasa.core.actions.forms - Activated the form 'flight_departure_form'.
2020-10-03 22:51:07 DEBUG rasa.core.actions.forms - No pre-filled required slots to validate.
2020-10-03 22:51:07 DEBUG rasa.core.actions.forms - Validating user input 'UserUttered(text: ?????? ????????????????, intent: {'id': 6883722366486273833, 'name': 'flight_departure_info', 'confidence': 0.9999984502792358}, entities: [{'start': 0, 'end': 12, 'value': 'el', 'entity': 'language', 'extractor': 'LanguageDetection', 'confidence': 0.8, 'processors': []}, {'entity': 'city', 'start': 4, 'end': 12, 'value': '????????????????', 'extractor': 'RegexEntityExtractor'}, {'entity': 'flying', 'start': 0, 'end': 3, 'value': '??????', 'extractor': 'RegexEntityExtractor'}, {'entity': 'flying', 'start': 0, 'end': 3, 'confidence_entity': 0.9989129304885864, 'value': '??????', 'extractor': 'DIETClassifier'}, {'entity': 'city', 'start': 4, 'end': 12, 'confidence_entity': 0.9877170920372009, 'value': '????????????????', 'extractor': 'DIETClassifier'}])'.
2020-10-03 22:51:07 DEBUG rasa.core.actions.forms - Validating extracted slots: {}
2020-10-03 22:51:07 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'validate_flight_departure_form'.
2020-10-03 22:51:07 DEBUG rasa.core.actions.forms - Request next slot 'sl_frm_flight_departure_info_city'
2020-10-03 22:51:07 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'action_ask_sl_frm_flight_departure_info_city'.
2020-10-03 22:51:07 DEBUG rasa.core.processor - Action 'flight_departure_form' ended with events '[<rasa.shared.core.events.ActiveLoop object at 0x7fd06006dfd0>, <rasa.shared.core.events.SlotSet object at 0x7fd06006dbe0>]'.

```

I cannot understand. There is a city detected in the user input, why the slot is not filled? And why the form has to ask again for filling the slot?

Let alone the fact, that despite the form wants to ask for a city, the message is never asked.

---

<div class="post-metadata">

**Author:** ![petasis](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@petasis](https://forum.rasa.com/u/petasis)\
**Post date:** [October 3, 2020, 9:56pm UTC](https://forum.rasa.com/t/rasa-2-0-how-are-forms-working/35425/2 "2020-10-03T21:56:23Z")

</div>

After spending a couple of hours, I understood why it does not work:

In FormAction() class, there is the extract\_other\_slots() method, run when the form activates. This decides what slots will be filled. It uses method entity\_is\_desired(), which does:

```
if (
            requested_slot_mapping.get("role") is None
            and requested_slot_mapping.get("group") is None
        ) or entity_type_of_slot_to_fill != requested_slot_mapping.get("entity"):
            slot_fulfils_entity_mapping = False

```

Which simply means, that the slot will be filled only if the role/group attributes have been defined, or if the slot has the same name as the entrity. Else, it will fail.

So, a simple slot definition like this:

```auto
sl_frm_flight_departure_info_city:
    - type: from_entity
      entity: city

```

will NEVER be initialised from the user input. And this is not in the documentation!

---

<div class="post-metadata">

**Author:** ![petasis](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@petasis](https://forum.rasa.com/u/petasis)\
**Post date:** [October 3, 2020, 11:58pm UTC](https://forum.rasa.com/t/rasa-2-0-how-are-forms-working/35425/3 "2020-10-03T23:58:29Z")

</div>

I have updated to rc3, and now I get an error:

```
  File "rasa/core/actions/forms.py", line 142, in _create_unique_entity_mappings
    for slot_mapping in slot_mappings:
TypeError: 'NoneType' object is not iterable

```

This is caused if a slot mapping does not have a type…

---

<div class="post-metadata">

**Author:** ![petasis](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@petasis](https://forum.rasa.com/u/petasis)\
**Post date:** [October 4, 2020, 12:18am UTC](https://forum.rasa.com/t/rasa-2-0-how-are-forms-working/35425/4 "2020-10-04T00:18:30Z")

</div>

After removing the slots causing problems from the form, now validation does not work:

```
2020-10-04 03:11:20 DEBUG rasa.core.actions.forms - Validating extracted slots: {'sl_frm_flight_departure_info_city': '????????????????'}
2020-10-04 03:11:20 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'validate_flight_departure_form'.

```

This is the code in the validation action:

> ```
> def run(
> self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
> ) -> List[EventType]:
> extracted_slots: Dict[Text, Any] = tracker.form_slots_to_validate()
> 
> validation_events = []
> print("FlightForm::run()===================================================", flush=True)
> print(self.name())
> print("extracted_slots:", extracted_slots, flush=True)
> 
> ```

The output is:

> ```
> FlightForm::run()===================================================
> validate_flight_departure_form
> extracted_slots: {}
> 
> ```

tracker.form\_slots\_to\_validate() returns an empty list!

---

<div class="post-metadata">

**Author:** ![petasis](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@petasis](https://forum.rasa.com/u/petasis)\
**Post date:** [October 4, 2020, 11:37pm UTC](https://forum.rasa.com/t/rasa-2-0-how-are-forms-working/35425/5 "2020-10-04T23:37:57Z")

</div>

> <https://github.com/RasaHQ/rasa-sdk/issues/269>
>
> \<!-- THIS INFORMATION IS MANDATORY - YOUR ISSUE WILL BE CLOSED IF IT IS MISSING.… If you don't know your Rasa version, use \`rasa --version\`. 
> Please format any code or console output with three ticks \`\`\` above and below.
> If you are asking a usage question (e.g. "How do I do xyz") please post your question on https://forum.rasa.com instead --\>
> 
> \*\*Rasa version\*\*: 2.0.0a4
> 
> \*\*Rasa SDK version\*\*: 2.0.0a4
> 
> \*\*Python version\*\*: 3.7.8
> 
> \*\*Operating system\*\* (windows, osx, ...): Ubuntu 18.04
> 
> \*\*Issue\*\*:
> tracker.form\_slots\_to\_validate() ignores slots to validate when called on form activation. I didn't try it with pre-filled slots, but the problem will probably be the same as with a slot filled with a \`from\_trigger\_intent\` mapping (I think it's the check to see if there's an active loop that causes this). Here's a simple example to test it: 
> 
> \*\*Command or request that led to error\*\*:
> \`\`\`
> rasa shell --debug
> Your input -\> /test\_form
> Asking other slot
> Your input -\> /affirm
> Form completed. Value is value\_to\_correct
> \`\`\`
> 
> \*\*Content of configuration file (config.yml)\*\* (if relevant):
> \`\`\`yml
> ...
> policies:
> - name: RulePolicy
> \`\`\`
> 
> \*\*Content of domain file (domain.yml)\*\* (if relevant):
> \`\`\`yml
> intents:
> - affirm
> - test\_form
> 
> actions:
> - validate\_test\_trigger\_intent\_form
> 
> forms:
> - test\_trigger\_intent\_form:
> filled\_with\_trigger\_intent:
> - type: from\_trigger\_intent
> intent: test\_form
> value: value\_to\_correct
> other\_slot: # Just to verify if value is validated later
> - type: from\_intent
> intent: affirm
> value: True
> 
> slots:
> filled\_with\_trigger\_intent:
> type: unfeaturized
> 
> other\_slot:
> type: unfeaturized
> 
> templates:
> utter\_ask\_other\_slot:
> - text: Asking other slot
> 
> utter\_form\_completed:
> - text: Form completed. Value is {filled\_with\_trigger\_intent}
> \`\`\`
> 
> \*\*Content of rules file (rules.yml)\*\* (if relevant):
> \`\`\`yml
> ...
> rules:
> - rule: test trigger intent validation
> steps:
> - intent: test\_form
> - action: test\_trigger\_intent\_form
> - active\_loop: test\_trigger\_intent\_form
> - active\_loop: null
> - action: utter\_form\_completed
> \`\`\`
> 
> \*\*Contents of actions.py\*\* (if relevant):
> \`\`\`python
> class ValidateTestTriggerIntentForm(Action):
> def name(self) -\> Text:
> return "validate\_test\_trigger\_intent\_form"
> 
> def run(
> self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
> ) -\> List\[EventType\]:
> extracted\_slots: Dict\[Text, Any\] = tracker.form\_slots\_to\_validate()
> 
> logger.info(f"Validating extracted slots: {extracted\_slots}")
> logger.info(tracker.events)
> 
> validation\_events: List\[EventType\] = \[\]
> 
> for slot\_name, slot\_value in extracted\_slots.items():
> if slot\_name == "filled\_with\_trigger\_intent" and slot\_value == "value\_to\_correct":
> validation\_events.append(SlotSet("filled\_with\_trigger\_intent", "corrected\_value"))
> 
> return validation\_events
> \`\`\`
> 
> Logs show that the correct events are there and core calls the validation action with the slot:
> 
> \*\*Action server logs for first interaction\*\*:
> \`\`\`
> ...
> action-server\_1 | 2020-09-15 18:16:03 INFO covidflow.actions.test\_trigger\_intent\_form - \[info \] Validating extracted slots: {} 
> action-server\_1 | 2020-09-15 18:16:03 INFO covidflow.actions.test\_trigger\_intent\_form - \[info \] \[{'event': 'action', 'timestamp': 1600193759.547206, 'name': 'action\_listen', 'policy': None, 'confidence': 1.0}, {'event': 'user', 'timestamp': 1600193763.3620577, 'text': '/test\_form', 'parse\_data': {'intent': {'name': 'test\_form', 'confidence': 1.0}, 'entities': \[\], 'text': '/test\_form', 'message\_id': 'b3562360e39546a685aea2ff0afa0b29', 'metadata': {}, 'intent\_ranking': \[{'name': 'test\_form', 'confidence': 1.0}\]}, 'input\_channel': 'cmdline', 'message\_id': 'b3562360e39546a685aea2ff0afa0b29', 'metadata': {}}, {'event': 'action', 'timestamp': 1600193763.3705964, 'name': 'test\_trigger\_intent\_form', 'policy': None, 'confidence': None}, {'event': 'slot', 'timestamp': 1600193763.370542, 'name': 'filled\_with\_trigger\_intent', 'value': 'value\_to\_correct'}\] 
> ...
> \`\`\`
> 
> \*\*Core logs for first interaction\*\*:
> \`\`\`
> ...
> 2020-09-15 18:42:58 DEBUG rasa.core.actions.forms - Activated the form 'test\_trigger\_intent\_form'.
> 2020-09-15 18:42:58 DEBUG rasa.core.actions.forms - No pre-filled required slots to validate.
> 2020-09-15 18:42:58 DEBUG rasa.core.actions.forms - Validating user input 'UserUttered(text: /test\_form, intent: {'name': 'test\_form', 'confidence': 1.0}, entities: \[\])'.
> 2020-09-15 18:42:58 DEBUG rasa.core.actions.forms - Extracted 'value\_to\_correct' for extra slot 'filled\_with\_trigger\_intent'.
> 2020-09-15 18:42:58 DEBUG rasa.core.actions.forms - Validating extracted slots: {'filled\_with\_trigger\_intent': 'value\_to\_correct'}
> 2020-09-15 18:42:58 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'validate\_test\_trigger\_intent\_form'.
> ...
> \`\`\`

So, this is a bug. Which means validation for forms in rasa 2.x is currently broken.

---

<div class="post-metadata">

**Author:** ![akelad](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/akelad/32/69_2.png) [@akelad](https://forum.rasa.com/u/akelad)\
**Post date:** [October 5, 2020, 8:08am UTC](https://forum.rasa.com/t/rasa-2-0-how-are-forms-working/35425/6 "2020-10-05T08:08:02Z")

</div>

Hey @petasis thanks for bringing that up, it’s being fixed in this [PR](https://github.com/RasaHQ/rasa-sdk/pull/276)

---

<div class="post-metadata">

**Author:** ![petasis](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@petasis](https://forum.rasa.com/u/petasis)\
**Post date:** [October 5, 2020, 8:37am UTC](https://forum.rasa.com/t/rasa-2-0-how-are-forms-working/35425/7 "2020-10-05T08:37:23Z")

</div>

Is there a timeplan when a new rasa 2.x version will be released with the fix? Is there a workaround for now?

Right now, what is do is that when “extracted\_slots” is None, I collect all slots that are not None and must be validated, and validate them. It happens only when slots have been filled from the 1st user utterance.

---

<div class="post-metadata">

**Author:** ![akelad](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/akelad/32/69_2.png) [@akelad](https://forum.rasa.com/u/akelad)\
**Post date:** [October 5, 2020, 8:50am UTC](https://forum.rasa.com/t/rasa-2-0-how-are-forms-working/35425/8 "2020-10-05T08:50:42Z")

</div>

The final release of version 2.0 is planned for this week (of course this isn’t a guarantee, there’s always a chance something goes wrong and it’s delayed). The version you’re using right now is still a release candidate, and so not suited for production yet. You could use the version of the SDK on that branch for now, and it’ll also be merged to master soon.

---

<div class="post-metadata">

**Author:** ![petasis](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@petasis](https://forum.rasa.com/u/petasis)\
**Post date:** [October 9, 2020, 11:15am UTC](https://forum.rasa.com/t/rasa-2-0-how-are-forms-working/35425/9 "2020-10-09T11:15:34Z")

</div>

@akelad Hi again. I just updated to rasa 2.0, and I am back at my original question: are forms working?

After so much effort to make my forms work in 2.0.0rc3, 2.0.0rc4, my forms do not work with rasa 2.0. And the documentation confusing. What is written in [Forms](https://rasa.com/docs/rasa/forms#validating-form-input) does not work for me.

---

<div class="post-metadata">

**Author:** ![akelad](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/akelad/32/69_2.png) [@akelad](https://forum.rasa.com/u/akelad)\
**Post date:** [October 9, 2020, 11:29am UTC](https://forum.rasa.com/t/rasa-2-0-how-are-forms-working/35425/10 "2020-10-09T11:29:48Z")

</div>

Sounds like you’ve asked your question in a different thread already - we’ll get back to you there.
