# Rules

**URL:** <https://forum.rasa.com/t/rules/40002>\
**Category:** Rasa Open Source\
**Created:** [February 9, 2021, 10:12am UTC](https://forum.rasa.com/t/rules/40002 "2021-02-09T10:12:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenan](https://avatars.discourse-cdn.com/v4/letter/j/977dab/32.png) [@jenan](https://forum.rasa.com/u/jenan)\
**Post date:** [February 9, 2021, 10:12am UTC](https://forum.rasa.com/t/rules/40002/1 "2021-02-09T10:12:46Z")

</div>

How to combine stories and rules when writing training data without making them contradict each other.

---

<div class="post-metadata">

**Author:** ![fkoerner](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/fkoerner/32/11784_2.png) [@fkoerner](https://forum.rasa.com/u/fkoerner)\
**Post date:** [February 10, 2021, 9:29am UTC](https://forum.rasa.com/t/rules/40002/2 "2021-02-10T09:29:28Z")

</div>

Hi there, not sure I’ve understood your question, but I’ll give it a shot, let me know if you were looking for something else.

Basically, rules are law. Any conversation sequence that matches the “beginning of a rule” has to result in the end of the rule, because the system will always complete the steps of the rule. For example, say you have a rule that looks like:

```auto
- rule: return greeting
  steps:
  - intent: greet
  - action: utter_greet

```

This means, anytime the user greets the bot, the bot **must greet back**. A story that contradicts this would look like:

```auto
 - story: rude bot
   steps:
   - intent: greet
   - action: utter_dont_talk_to_me

```

This story contradicts the rule, because `action: utter_greet` didn’t follow `intent: greet`. Any story that contains some rule steps must contain the entire rule step sequence or disambiguate somehow (for example with slots, or a condition).

---

<div class="post-metadata">

**Author:** ![BarMin](https://avatars.discourse-cdn.com/v4/letter/b/0ea827/32.png) [@BarMin](https://forum.rasa.com/u/BarMin)\
**Post date:** [February 10, 2021, 10:26am UTC](https://forum.rasa.com/t/rules/40002/3 "2021-02-10T10:26:08Z")

</div>

Hi!

Would it be possible for you to check my own thread, where I mention similar problem with rules/stories?

> [@Problem with rules](http://forum.rasa.com/t/problem-with-rules/39343):
>
> HI! Could someone explain me, why this doesn’t work? I have a rule and a story defined as: - rule: submit make appointment form condition: - active\_loop: make\_appointment\_form steps: - action: make\_appointment\_form - active\_loop: null - action: utter\_make\_appointment\_slots\_values - action: utter\_ask\_data\_correctness - intent: affirm - action: action\_submit\_make\_appointment\_form - story: overall make appointment steps: - intent: greet+make\_appointment - ac…

I didn’t obtain viable response on what’s actually wrong in my case and still - I don’t understand why it’s not working.

---

<div class="post-metadata">

**Author:** ![fkoerner](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/fkoerner/32/11784_2.png) [@fkoerner](https://forum.rasa.com/u/fkoerner)\
**Post date:** [February 10, 2021, 10:50am UTC](https://forum.rasa.com/t/rules/40002/4 "2021-02-10T10:50:51Z")

</div>

@BarMin, yep, see my response there! 🙂

---

<div class="post-metadata">

**Author:** ![jenan](https://avatars.discourse-cdn.com/v4/letter/j/977dab/32.png) [@jenan](https://forum.rasa.com/u/jenan)\
**Post date:** [February 14, 2021, 12:43pm UTC](https://forum.rasa.com/t/rules/40002/5 "2021-02-14T12:43:45Z")

</div>

Hi, which means the rules and the stories need to be the same? Also, how can I link stories to each other

---

<div class="post-metadata">

**Author:** ![fkoerner](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/fkoerner/32/11784_2.png) [@fkoerner](https://forum.rasa.com/u/fkoerner)\
**Post date:** [February 14, 2021, 5:02pm UTC](https://forum.rasa.com/t/rules/40002/6 "2021-02-14T17:02:07Z")

</div>

Well, they don’t have to be the same. Generally I’d expect a story to be longer than a rule. What’s important is that if the first steps of a rule match steps in the story the outcome in both the rule and the story must be the same, **unless** you disambiguate them with slots or a condition. So for example:

```auto
- story: sad path 1
  steps:
  - intent: greet
  - action: utter_greet
  - intent: mood_unhappy
  - action: utter_cheer_up
  - action: utter_did_that_help
  - intent: affirm
  - action: utter_happy

```

Can’t be paired with the rule:

```auto
rules:
 - rule: 
   steps:
   - intent: mood_unhappy
   - action: utter_cheer_up
   - action: utter_ask_how_are_you

```

Because the bot can’t learn what action to take after seeing a conversation like below. Should it be `utter_ask_how_are_you` or `utter_did_that_help`?

```auto
   user: mood_unhappy
   bot: utter_cheer_up

```

I’m not sure what you mean by linking stories. You shouldn’t have to do anything additional to allow the bot to transition from one story to another. Depending on the policy you have, the bot will predict the next action for an exact match, or a similar story. For example:

“The `MemoizationPolicy` remembers the stories from your training data. It checks if the current conversation matches the stories in your `stories.yml` file. If so, it will predict the next action from the matching stories of your training data” ([source](https://rasa.com/docs/rasa/policies/#memoization-policy))

`TEDPolicy` and `AugmentedMemoizationPolicy` will generalise, meaning they can attempt to predict the next action even if they haven’t seen this sequence of events before.

---

<div class="post-metadata">

**Author:** ![fkoerner](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/fkoerner/32/11784_2.png) [@fkoerner](https://forum.rasa.com/u/fkoerner)\
**Post date:** [February 14, 2021, 5:04pm UTC](https://forum.rasa.com/t/rules/40002/7 "2021-02-14T17:04:31Z")

</div>

You can try running `rasa data validate` to validate your **stories** , not the rules. But `RulePolicy` will abort training if there is a conflict between your rules and stories, so you’ll be alerted and have the opportunity to fix it. If you feel those error messages are confusing, you can feel free to ask a followup question here and tag me.
