Rasa 2.0: How to resolve conflicting rules?

Hi all,

I am facing a problem regarding rules for a form. I have a form, ok with happy paths, I cannot get the unhappy paths working (i.e. the user has requested to stop, the user has insulted the bot, and the user has used chitchat). Initially I tried to user rules, never managed to remove contradictions, then switched to stories, “rasa data validate --max-history 20” passes, but again contradictions during training. Finally, I used “rasa interactive” (which is not easy if you have a lot of utter_*, the list is large), and created the stories with rasa interactive: The stories I got (I have removed some slots, as forms do not work well in rasa interactive) are:

- story: flight departure information - unhappy path - insult - el
  steps:
  - intent: flight_departure_info
  - slot_was_set:
    - language: el
  - action: flight_departure_form
  - active_loop: flight_departure_form
  - intent: insult
    entities:
    - entity: language
    - value: el
  - slot_was_set:
    - language: el
  - action: action_deactivate_loop
  - active_loop: null
  - action: utter_respond_insult_el
  - action: utter_flight_restart_el
  - action: action_reset_all_slots_flight_departure_form
  - slot_was_set:
    - deactivate_form: null

- story: flight departure information - unhappy path - insult - en
  steps:
  - intent: flight_departure_info
  - slot_was_set:
    - language: en
  - action: flight_departure_form
  - active_loop: flight_departure_form
  - intent: insult
    entities:
    - entity: language
    - value: en
  - slot_was_set:
    - language: en
  - action: action_deactivate_loop
  - active_loop: null
  - action: utter_respond_insult_en
  - action: utter_flight_restart_en
  - action: action_reset_all_slots_flight_departure_form
  - slot_was_set:
    - deactivate_form: null

During training, I get the following error: (rasa validate reports no error)

InvalidRule: Contradicting rules or stories found ??

  • the prediction of the action ‘action_deactivate_loop’ in story ‘flight departure information - unhappy path - insult - en’ is contradicting with another rule or story.
  • the prediction of the action ‘action_deactivate_loop’ in story ‘flight departure information - unhappy path - insult - el’ is contradicting with another rule or story.

How can I resolve this contradiction? In my domain, I have:

  language:
    type: categorical
    values:
    - el
    - en
    influence_conversation: true

Since the language slot has a different value, why are the rules contradicting?

1 Like

To simplify search for solution, I commented out all stories using action_deactivate_loop, except two. Event these two are contradicting:

- story: flight departure information - unhappy path - stop - el
  steps:
  - intent: flight_departure_info
  - slot_was_set:
    - language: el
  - action: flight_departure_form
  - active_loop: flight_departure_form
  - intent: stop
    entities:
    - entity: language
    - value: el
  - slot_was_set:
    - language: el
  - action: utter_ask_continue_el
  - intent: deny
    entities:
    - entity: language
    - value: el
  - slot_was_set:
    - language: el
  - action: action_deactivate_loop
  - active_loop: null
  - action: utter_flight_restart_el
  - action: action_reset_all_slots_flight_departure_form
  - slot_was_set:
    - deactivate_form: null

- story: flight departure information - unhappy path - insult - el
  steps:
  - intent: flight_departure_info
  - slot_was_set:
    - language: el
  - action: flight_departure_form
  - active_loop: flight_departure_form
  - intent: insult
    entities:
    - entity: language
    - value: el
  - slot_was_set:
    - language: el
  - action: action_deactivate_loop
  - active_loop: null
  - action: utter_respond_insult_el
  - action: utter_flight_restart_el
  - action: action_reset_all_slots_flight_departure_form
  - slot_was_set:
    - deactivate_form: null
  • the prediction of the action ‘action_deactivate_loop’ in story ‘flight departure information - unhappy path - insult - el’ is contradicting with another rule or story.

While this is no long term solution you might want to turn off the contradiction check and see if the stoies work as expected (preferably by MemoizationPolicy). If they do so it might be a bug.

policies:
  - name: "RulePolicy"
    check_for_contradictions: false

@NOlbert Thanks for the tip. But the contradictions are on stories. My rules are:

- rule: Activate form (Departure)
  steps:
  - intent: flight_departure_info
  - action: flight_departure_form
  - active_loop: flight_departure_form

- rule: Deactivate form (Departure)
  condition:
  - active_loop: flight_departure_form
  - slot_was_set:
    - deactivate_form: flight_departure_form
  steps:
  - action: flight_departure_form
  - active_loop: null
  - action: action_reset_all_slots_flight_departure_form

- rule: Submit form (Departure)
  condition:
  # Condition that form is active.
  - active_loop: flight_departure_form
  steps:
  # Form is deactivated
  - action: flight_departure_form
  - active_loop: null
  - action: action_reset_all_slots_flight_departure_form

They do not contain at all action_deactivate_loop.

This contradiction means that there is a rule that predicts a different action then action_deactivate_loop for this story

Do your rules contain intent insult?

@Ghostvv No, they don’t. All the rules are listed two messages above. One rule for activating the form, one for deactivating it, and one for resetting slots after “submit”.

@Ghostvv But why? active_deactivate_loop is used only twice, in these two rules, and one is after insult, and the other after deny.

I have also a story that uses insult:

- story: Insult
  steps:
  - intent: insult
  - action: utter_respond_insult_el

could you please share your domain file and a minimum set of rules/stories to reproduce this error

@Ghostvv Wouldn’t this require also the form? The custom actions?

in order to train custom actions are not needed

@Ghostvv Can you please try with the attached file? rasa2.zip (8.7 KB)

your first rule is:

- rule: Map "insult" to "utter_respond_insult_el"
  steps:
  - intent: insult
  - action: utter_respond_insult

which always predict utter_respond_insult after insult which is contradicting to your stories

Our contradicting error message is not very clear. I’m working on the PR to update it

if you want the insult rule to happen only outside the form, you can add:

condition:
- active_loop: null

I want to stop the form, if an insult was given to the bot.

Ok, I understood, you are talking about the rules outside the form, where I map insults/chitchat to answers. These were automatically created by the migration, as I had in the domain triggers.

I think you have found the cause. Adding this condition to all the rules that were produced during the migration from rasa 1.x to 2.x, and my form rules are not anymore in conflict!

Thank you!

(Maybe it is a good idea rasa data convert to use the condition when migrating files?)

not sure, it is a general solution