How to combine stories and rules for form filling - ERROR: 'contradicting rules and stories'

The documentation is not clear on how to combine stories and rules when writing training data for an intent that involves form filling. I wrote rules for filling forms that look like this:

- rule: Activate email form
  steps:
  - intent: lookup_mail_server
  - action: email_form
  - active_loop: email_form
    - rule: Submit email form
      condition:
      - active_loop: email_form
      steps:
      - action: email_form
      - active_loop: null

And stories look like this:

- story: look up mail server 
  steps:
  - intent: lookup_mail_server
  - action: action_interject
  - action: email_form
  - active_loop: email_form
  - active_loop: null
  - action: action_fetch_mail_server
  - action: action_follow_up

But when I train the model I get an ERROR saying ‘contradicting rules and stories’.

My understanding is that you can have a story without a rule but you cant have a rule without a story or the action prediction wont work. Is that correct or can someone clarify the dependency relationship between the two?

Can someone please provide a full example of how to write a story and rule for an intent that involves form filling? Or how to know when only a story OR a rule is necessary?

2 Likes

Hey @tatianaf your rules don’t need stories to function, you can have a bot that consists only of rules if you wanted to. You can find a description on when to use rules vs stories in this docs page.

Your story is contradicting in this case in multiple places (it would be contradicting even if you were using only stories, and not rules):

- story: look up mail server 
  steps:
  - intent: lookup_mail_server
  - action: action_interject

vs

- rule: Activate email form
  steps:
  - intent: lookup_mail_server
  - action: email_form

and

- action: email_form
  - active_loop: email_form
  - active_loop: null
  - action: action_fetch_mail_server

vs

condition:
      - active_loop: email_form
      steps:
      - action: email_form
      - active_loop: null

The story for the email form submission should probably be extended to include the action_fetch_mail_server:

- rule: Submit email form
      condition:
      - active_loop: email_form
      steps:
      - action: email_form
      - active_loop: null
      - action: action_fetch_mail_server
      - action: action_follow_up

The action_interject i’m not sure what that is for.

1 Like

I’ve removed the rules because I found the story format to be more straight forward and there are no conflicts now. Ive read the docs multiple times but I still dont think there’s a clear sense given for when rules are actually necessary instead of just using stories… Maybe you guys could do a better job of giving more in-depth examples or tutorials that better illustrate scenarios where rules should be used or stories and rules should be used together. It seems to be more “intuitive” than logical so longer examples/tutorial would do a better job of offering that intuition.

4 Likes

You can take a look at the example of rasa-demo here: rasa-demo/data at rasa-2.0 · RasaHQ/rasa-demo · GitHub

I’m not sure I fully understand the confusion around the rule format - the format is almost identical to stories, with the exception of the condition. Could you clarify which part is confusing?

As for when to use rules vs stories, there’s a list of when to use rules in the documentation page I linked:

Also happy to hear what you would like to see in terms of clarification there.

A simple way to think about the mechanisms of rules vs stories is that if you specify a rule like this:

- rule: greet
  steps:
    - intent: greet
    - action: utter_greet 

it will always work exactly as specified, regardless of how many times the user says “greet” over and over again. If you only have a story for this, it’s not guaranteed that that will work every time.

1 Like

Thanks for your answer. Ive read the docs, including the excerpt you shared and when I read it, it wasnt clear why you would rules for any of those when you could also use stories- the advantage was not clear. Although the last sentence of your answer does offer more clarification “it will always work exactly as specified, regardless of how many times the user says “greet” over and over again. If you only have a story for this, it’s not guaranteed that that will work every time.” So I guess stories can replace all rules but not all rules can replace stories because sometimes stories can be used to capture varied behavior where as rules can only capture consistent behavior. Stories are training data used for the prediction model but rules are hardcoded conditions not training data?

1 Like

Sorry if it seems Im being overly detailed here but we’ve had a lot of issues with our use of forms and writing stories for forms in Rasa 1 and the main reason for us migrating to Rasa 2 immediately is to address those issues. The docs makes it seem simple but in actual production use its incredibly nuanced and easy to get wrong/unexpected behavior.

6 Likes

@tatianaf Your absolutely right. I wonder why don’t these guys develop a friendly documentation.

@Rasa I have watched many Tutorials in Youtube, which is 1.8, And you guys released 2.0 with major updated and not yet released its tutorials, the documentation which is available in your website are not friendly. :frowning:

1 Like

oops, I thought I had answered this a while ago, but yes @tatianaf that summary sums it up.

@susajsnair we’re happy to address any specific feedback you have on the documentation if you share it. There are plenty of example bots available which you can use as a reference instead of some of the videos for now:

Updates to the videos will be coming eventually, but you have to understand we’re a small team, and can only work so fast.

4 Likes

Agree that rules, when to use them and how to use them with stories is confusing and under-documented.

3 Likes

@akelad i actually mean, if someone comes and try to understand newly, will try to work with RASA 2.x and there is no more proper tutorials available, The docs which are available in website is good for those who has already part of it, not for newbies.

3 Likes

Hi all.

My name is Vincent. I’m part of the devrel team and I’ll be making some extra content on this topic. I’ve already made a video on the idea behind the RulePolcy from the ML perspective but I’ll work on making a proper blog post/guide on rules too. I’ll also create a git repo that contains a full example of how rules interact with forms.

I’ll use this thread as inspiration, but if there are other specific pain points you’re welcome to mention them in this thread.

4 Likes

To anybody interested, here’s a first guide. It might help explain why rules were introduced.

2 Likes