# Triggering a rule when the user does not fill a slot

**URL:** <https://forum.rasa.com/t/triggering-a-rule-when-the-user-does-not-fill-a-slot/50969>\
**Category:** Rasa Open Source\
**Created:** [January 29, 2022, 1:01am UTC](https://forum.rasa.com/t/triggering-a-rule-when-the-user-does-not-fill-a-slot/50969 "2022-01-29T01:01:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![braddock](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/braddock/32/19182_2.png) [@braddock](https://forum.rasa.com/u/braddock)\
**Post date:** [January 29, 2022, 1:01am UTC](https://forum.rasa.com/t/triggering-a-rule-when-the-user-does-not-fill-a-slot/50969/1 "2022-01-29T01:01:01Z")

</div>

I wish to have a rule trigger when the user does not provide valid input to a form slot. For example, the categorical slot question may be a yes or no answer, but the user might type ‘I don’t know’. I need to fall back but I want a fallback that is specific for that question/slot.

Any help is appreciated.

I’ve tried many things. The following is what I think should work, but it fails with a cryptic error:

“the prediction of the action ‘utter\_something\_else’ in rule ‘Something else was said’ is contradicting with rule(s) ‘handling active loops and forms - yes\_or\_no\_form - action\_listen’ which predicted action ‘action\_listen’.”

```auto
- rule: Yes was said
  condition:
    - active_loop: yes_or_no_form
    - slot_was_set:
        - requested_slot: null
        - yes_or_no: yes
  steps:
    - action: yes_or_no_form
    - active_loop: null
    - slot_was_set:
        - requested_slot: null
        - yes_or_no: yes
    - action: utter_yes

- rule: No was said
  condition:
    - active_loop: yes_or_no_form
    - slot_was_set:
        - requested_slot: null
        - yes_or_no: no
  steps:
    - action: yes_or_no_form
    - active_loop: null
    - slot_was_set:
        - requested_slot: null
        - yes_or_no: no
    - action: utter_no

- rule: Something else was said
  condition:
    - active_loop: yes_or_no_form
    - slot_was_set:
        - requested_slot: yes_or_no_form
        - yes_or_no: null
  steps:
    - action: yes_or_no_form
    - active_loop: yes_or_no_form
    - slot_was_set:
        - requested_slot: yes_or_no
        - yes_or_no: null
    - action: utter_something_else

```

---

<div class="post-metadata">

**Author:** ![E-dC](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@E-dC](https://forum.rasa.com/u/E-dC)\
**Post date:** [January 29, 2022, 5:10pm UTC](https://forum.rasa.com/t/triggering-a-rule-when-the-user-does-not-fill-a-slot/50969/2 "2022-01-29T17:10:34Z")

</div>

Hi @braddock ,

What is the type of your `yes_or_no` slot? If it’s a `text` slot, then only the presence or absence of text in the slot counts when influencing conversation.  
This means that `yes_or_no` having the value “yes” or “no” is actually _the same thing_, and `yes_or_no` being `null` is the only other situation. See [Domain](https://rasa.com/docs/rasa/domain/#text-slot:)

> If `influence_conversation` is set to `true`, the assistant’s behavior will change depending on whether the slot is set or not. Different texts do not influence the conversation any further.

So, rules “Yes was said” and “No was said” are contradicting one another, because the conditions are identical (`yes_or_no` is set (value doesn’t matter), `active_loop` is `yes_or_no_form`), but the steps to follow are different.

To achieve what you’re trying to do, you may want to use slot type `bool`

> If `influence_conversation` is set to `true`, the assistant’s behavior will change depending on whether the slot is empty, set to `true` or set to `false`. **Note that an empty `bool` slot influences the conversation differently than if the slot was set to `false`.**

or `categorical`:

> If `influence_conversation` is set to `true`, the assistant’s behavior will change depending on the concrete value of the slot. This means the assistant’s behavior is different depending on whether the slot in the above example has the value `low`, `medium`, or `high`.

Hope that helps

---

<div class="post-metadata">

**Author:** ![braddock](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/braddock/32/19182_2.png) [@braddock](https://forum.rasa.com/u/braddock)\
**Post date:** [January 29, 2022, 8:36pm UTC](https://forum.rasa.com/t/triggering-a-rule-when-the-user-does-not-fill-a-slot/50969/3 "2022-01-29T20:36:08Z")

</div>

Hi Etienne, Thanks so much for the response. The slot is categorical, and influence\_conversation is set to True. So the training “contradicting” error is still a mystery to me.

Here is my slot and form definition:

```auto
slots:
  yes_or_no:
    type: categorical
    influence_conversation: true
    values:
      - yes
      - no
    mappings:
      - type: from_intent
        intent: affirm
        value: yes
        conditions:
          - active_loop: yes_or_no_form
            requested_slot: yes_or_no
      - type: from_intent
        intent: deny
        value: no
        conditions:
          - active_loop: yes_or_no_form
            requested_slot: yes_or_no

forms:
  yes_or_no_form:
    required_slots:
      - yes_or_no

```

---

<div class="post-metadata">

**Author:** ![E-dC](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@E-dC](https://forum.rasa.com/u/E-dC)\
**Post date:** [January 31, 2022, 2:08pm UTC](https://forum.rasa.com/t/triggering-a-rule-when-the-user-does-not-fill-a-slot/50969/4 "2022-01-31T14:08:04Z")

</div>

In that case I’m unsure what the problem is… Perhaps see if there are any other rules or stories in your training data which are referencing the form, and check that your config includes the `RulePolicy`.

In your situation, I would also probably try starting with a single rule, train, and then re-adding the remainder one by one in order to see at which point the contradiction appears.

Perhaps one last idea would be to try to explicitly create a third “unknown” value in your categorical slot and fallback to this when the user doesn’t say “yes” or “no”, and see it that works. That being said, like you I would expect `null` to work fine for that.

```auto
slots:
  yes_or_no:
    type: categorical
    influence_conversation: true
    values:
      - yes
      - no
    mappings:
      - type: from_intent
        intent: affirm
        value: yes
        conditions:
          - active_loop: yes_or_no_form
            requested_slot: yes_or_no
      - type: from_intent
        intent: deny
        value: no
        conditions:
          - active_loop: yes_or_no_form
            requested_slot: yes_or_no
      - type: from_intent
        value: unknown
        not_intent:
          - affirm
          - deny
        conditions:
          - active_loop: yes_or_no_form
            requested_slot: yes_or_no

```

Hope that helps

---

<div class="post-metadata">

**Author:** ![braddock](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/braddock/32/19182_2.png) [@braddock](https://forum.rasa.com/u/braddock)\
**Post date:** [January 31, 2022, 5:33pm UTC](https://forum.rasa.com/t/triggering-a-rule-when-the-user-does-not-fill-a-slot/50969/5 "2022-01-31T17:33:45Z")

</div>

Thanks Etienne, it was a good idea, but when I try to run it in the shell I get

```auto
UserWarning: Slot 'yes_or_no' uses a 'from_intent' mapping for a non-existent intent 'None'. Skipping slot extraction because of invalid mapping.

```

then it fails to run the form at all. It seems like it doesn’t like a from\_intent mapping with only not\_intent’s specified?

This is a toy example. I’ve built it from scratch just to test this behavior (which was causing my problems in a much larger project).

My slots now look like:

```auto
slots:
  yes_or_no:
    type: categorical
    influence_conversation: true
    values:
      - yes
      - no
      - undefined
    mappings:
      - type: from_intent
        intent: affirm
        value: yes
        conditions:
          - active_loop: yes_or_no_form
            requested_slot: yes_or_no
      - type: from_intent
        intent: deny
        value: no
        conditions:
          - active_loop: yes_or_no_form
            requested_slot: yes_or_no
      - type: from_intent
        value: undefined
        not_intent:
          - affirm
          - deny
        conditions:
          - active_loop: yes_or_no_form
            requested_slot: yes_or_no

```

Rasa version info:

```auto
$ rasa --version
Rasa Version : 3.0.5
Minimum Compatible Version: 3.0.0
Rasa SDK Version : 3.0.3
Rasa X Version : None
Python Version : 3.8.3
Operating System : Linux-5.4.0-96-generic-x86_64-with-glibc2.10

```

---

<div class="post-metadata">

**Author:** ![E-dC](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@E-dC](https://forum.rasa.com/u/E-dC)\
**Post date:** [February 3, 2022, 1:50pm UTC](https://forum.rasa.com/t/triggering-a-rule-when-the-user-does-not-fill-a-slot/50969/6 "2022-02-03T13:50:18Z")

</div>

Hi @braddock ,

In the end, the simplest approach might be to also explicitly list the intents for which `undefined` may be triggered…

```auto
      - type: from_intent
        value: undefined
        intent:
          - greet
          - dont_know
          - thanks
          # ...
        not_intent:
          - affirm
          - deny
        conditions:
          - active_loop: yes_or_no_form
            requested_slot: yes_or_no

```

I’ve done something similar in the past once, although it was with a story: it’s not pretty but it worked 😕

Alternatively, it may be possible to simplify/bypass the rules and complex conditions using custom actions/customizing the form: [Forms](https://rasa.com/docs/rasa/forms/#advanced-usage)

---

<div class="post-metadata">

**Author:** ![Nick](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nick/32/20507_2.png) [@Nick](https://forum.rasa.com/u/Nick)\
**Post date:** [May 7, 2022, 3:30am UTC](https://forum.rasa.com/t/triggering-a-rule-when-the-user-does-not-fill-a-slot/50969/7 "2022-05-07T03:30:14Z")

</div>

Hi, @E-dCI try to define lists of intents for the optional parameters `intent`. When I run the model, There is a Warning: `UserWarning: Slot 'should_continue' uses a 'from_intent' mapping for a non-existent intent '['affirm', 'learn_more', 'thanks']'. Skipping slot extraction because of invalid mapping.`

```auto
should_continue:
    type: bool
    influence_conversation: false
    mappings:
    - type: from_intent
      intent: 
      - affirm
      - learn_more
      - thanks
      value: true
      conditions:
      - active_loop: continue_form
        requested_slot: should_continue
    - type: from_intent
      intent: deny
      value: false

```
