# How to deal with stories and rule which validate negative and edge cases

**URL:** <https://forum.rasa.com/t/how-to-deal-with-stories-and-rule-which-validate-negative-and-edge-cases/63035>\
**Category:** Rasa Open Source\
**Created:** [August 15, 2024, 9:05am UTC](https://forum.rasa.com/t/how-to-deal-with-stories-and-rule-which-validate-negative-and-edge-cases/63035 "2024-08-15T09:05:17Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![TrishaChetani](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/trishachetani/32/24501_2.png) [@TrishaChetani](https://forum.rasa.com/u/TrishaChetani)\
**Post date:** [August 15, 2024, 9:05am UTC](https://forum.rasa.com/t/how-to-deal-with-stories-and-rule-which-validate-negative-and-edge-cases/63035/1 "2024-08-15T09:05:17Z")

</div>

Stories.yml

```auto
version: "3.1"

stories:
- story: bot_launch
  steps:
    - action: action_show_help_on_launch

- story: happy path
  steps:
  - action: utter_greet
  - action: utter_show_possible_list_option

- 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

- story: sad path 2
  steps:
    - intent: greet
    - action: utter_greet
    - intent: mood_unhappy
    - action: utter_cheer_up
    - action: utter_did_that_help
    - intent: deny
    - action: utter_goodbye

- story: help_request
  steps:
    - intent: ask_for_help
    - action: utter_help

- story: ask_current_weather
  steps:
    - intent: ask_current_weather
    - action: utter_ask_current_weather

- story: ask_forecast
  steps:
    - intent: ask_forecast
    - action: utter_ask_forecast

- story: ask_historical_weather
  steps:
    - intent: ask_historical_weather
    - action: utter_ask_historical_weather

- story: ask_severe_weather_alerts
  steps:
    - intent: ask_severe_weather_alerts
    - action: utter_ask_severe_weather_alerts

- story: ask_air_quality
  steps:
    - intent: ask_air_quality
    - action: utter_ask_air_quality

- story: Get weather information for valid city
  steps:
    - intent: request_current_weather_city
      entities:
        - city: "Berlin"
    - action: action_validate_city_info
    - slot_was_set:
        - city: "Berlin"
    - action: action_get_weather_info_current
    - action: utter_show_possible_list_option

- story: Get weather information for invalid city
  steps:
    - intent: request_current_weather_city
      entities:
        - city: "abc"
        - input_validity: invalid_city
    - action: action_validate_city_info
    - slot_was_set:
        - city: null
        - input_validity: invalid_city
    - action: utter_request_city
    - intent: inform_city
    - slot_was_set:
      - city: text
      - input_validity: valid
    - action: action_get_weather_info_current
    - action: utter_show_possible_list_option

- story: Get weather information with different options
  steps:
    - intent: inform_city
      entities:
      - city: "Berlin"
    - slot_was_set:
      - city: text
      - input_validity: valid
    - action: action_get_weather_info_current
    - action: utter_show_possible_list_option

- story: Get weather information with ZIP code and country code
  steps:
    - intent: request_current_weather_zipcode_countrycode
      entities:
        - zipcode: "10001"
        - country_code: "US"
    - action: action_validate_zip_code_current_weather
    - action: action_validate_country_code_current_weather
    - slot_was_set:
        - zipcode: "10001"
        - country_code: "US"
        - input_validity: valid
    - action: action_get_zipcode_weather_current_weather
    - action: utter_show_possible_list_option

- story: Handle ZIP code without country code and correction
  steps:
    - intent: request_current_weather_zipcode_countrycode
      entities:
        - zipcode: "90210"
        - country_code: null
    - action: action_validate_zip_code_current_weather
    - action: action_validate_country_code_current_weather
    - slot_was_set:
        - zipcode: "90210"
        - country_code: null
        - input_validity: invalid_country_code
    - action: utter_ask_for_correct_countrycode
    - intent: inform_countrycode
      entities:
        - country_code: "DE"
    - action: action_validate_country_code_current_weather
    - slot_was_set:
        - zipcode: "90210"
        - country_code: "DE"
        - input_validity: valid
    - action: action_get_zipcode_weather_current_weather
    - action: utter_show_possible_list_option

- story: Handle invalid ZIP code input and correction
  steps:
    - intent: request_current_weather_zipcode_countrycode
      entities:
        - zipcode: "99999"
        - country_code: "US"
    - action: action_validate_zip_code_current_weather
    - action: action_validate_country_code_current_weather
    - slot_was_set:
        - zipcode: "99999"
        - country_code: "US"
        - input_validity: invalid_zipcode
    - action: utter_ask_for_correct_zipcode
    - intent: inform_zipcode
      entities:
        - zipcode: "90210"
    - action: action_validate_zip_code_current_weather
    - slot_was_set:
        - zipcode: "90210"
        - country_code: "US"
        - input_validity: valid
    - action: action_get_zipcode_weather_current_weather
    - action: utter_show_possible_list_option

- story: Handle request for historical weather with complete information
  steps:
  - intent: request_historical_weather_daterange_city
    entities:
    - start_date: "2024-03-01"
    - end_date: "2024-03-07"
    - city: "Madrid"
  - action: action_validate_city_info
  - action: action_validate_date_range_historical_weather
  - slot_was_set:
    - city: "Madrid"
    - start_date: "2024-03-01"
    - end_date: "2024-03-07"
  - action: action_get_past_weather_info
  - action: utter_show_possible_list_option

- story: Handle historical weather with missing end date and correction
  steps:
  - intent: request_historical_weather_daterange_city
    entities:
    - start_date: "2024-01-01"
    - end_date: null
    - city: "London"
  - action: action_validate_city_info
  - action: action_validate_start_date
  - slot_was_set:
    - city: "London"
    - start_date: "2024-01-01"
    - end_date: null
  - action: utter_ask_for_end_date
  - intent: inform_enddate
    entities:
    - start_date: "2024-01-01"
    - end_date: "2024-01-07"
    - city: "London"
  - action: action_validate_city_info
  - action: action_validate_date_range_historical_weather
  - slot_was_set:
     - city: "London"
     - start_date: "2024-01-01"
     - end_date: "2024-01-07"
  - action: action_get_past_weather_info
  - action: utter_show_possible_list_option

- story: Handle historical weather with missing start date and correction
  steps:
  - intent: request_historical_weather_daterange_city
    entities:
    - start_date: null
    - end_date: "2024-01-01"
    - city: "London"
  - action: action_validate_city_info
  - action: action_validate_end_date
  - slot_was_set:
    - city: "London"
    - end_date: "2024-01-01"
    - start_date: null
  - action: utter_ask_for_start_date
  - intent: inform_startdate
    entities:
    - start_date: "2024-01-01"
    - end_date: "2024-01-07"
    - city: "London"
  - action: action_validate_city_info
  - action: action_validate_date_range_historical_weather
  - slot_was_set:
    - city: "London"
    - start_date: "2024-01-01"
    - end_date: "2024-01-07"
  - action: action_get_past_weather_info
  - action: utter_show_possible_list_option

- story: Handle invalid city for historical weather and correction
  steps:
  - intent: request_historical_weather_daterange_city
    entities:
    - start_date: "2023-11-01"
    - end_date: "2023-11-10"
    - city: "FakeCity"
  - action: action_validate_city_info
  - action: action_validate_date_range_historical_weather
  - slot_was_set:
    - start_date: "2023-11-01"
    - end_date: "2023-11-10"
    - city: "FakeCity"
  - action: utter_ask_for_correct_city
  - intent: inform_city
  - action: action_validate_city_info
  - slot_was_set:
    - start_date: "2023-11-01"
    - end_date: "2023-11-10"
    - city: text
  - action: action_get_past_weather_info
  - action: utter_show_possible_list_option

- story: Handle invalid date range for historical weather
  steps:
  - intent: request_historical_weather_daterange_city
    entities:
    - start_date: "2024-03-15"
    - end_date: "2024-03-10"
    - city: "Berlin"
  - action: action_validate_city_info
  - action: action_validate_date_range_historical_weather
  - slot_was_set:
    - city: "Berlin"
    - start_date: "2024-03-15"
    - end_date: "2024-03-10"
  - action: utter_invalid_daterange
  - action: utter_ask_for_correct_daterange
  - intent: inform_startdate
    entities:
    - start_date: "2024-03-10"
  - intent: inform_enddate
    entities:
    - end_date: "2024-03-15"
  - action: action_validate_date_range_historical_weather
  - slot_was_set:
    - city: "Berlin"
    - start_date: "2024-03-10"
    - end_date: "2024-03-15"
  - action: action_get_past_weather_info
  - action: utter_show_possible_list_option

- story: Handle request for future weather based on time period forecast
  steps:
  - intent: request_weather_forecast_timeperiod_and_city
    entities:
    - city: "Tokyo"
    - time_period: "next week"
  - action: action_validate_city_info
  - action: action_validate_time_period_forecast
  - slot_was_set:
    - city: "Tokyo"
    - time_period: "next week"
  - action: action_get_future_weather_info
  - action: utter_show_possible_list_option

- story: Handle request for forecast with city and days provided
  steps:
  - intent: request_weather_forecast_days_and_city
    entities:
    - city: "Miami"
    - days: 7
  - action: action_validate_city_info
  - action: action_validate_days_forecast
  - slot_was_set:
    - city: "Miami"
    - days: 7
    - input_validity: valid
  - action: action_get_future_weather_info
  - action: utter_show_possible_list_option

- story: Handle invalid number of days input and correction
  steps:
  - intent: request_weather_forecast_days_and_city
    entities:
    - city: "New York"
    - time_period: "Many"
  - action: action_validate_city_info
  - action: action_validate_days_forecast
  - slot_was_set:
    - city: "New York"
    - time_period: "Many"
  - action: utter_invalid_timeperiod
  - intent: inform_timeperiod
  - action: action_validate_days_forecast
  - slot_was_set:
    - time_period: "this week"
    - city: "New York"
  - action: action_get_future_weather_info
  - action: utter_show_possible_list_option

- story: Handle date too far in future for weather forecast
  steps:
  - intent: request_weather_forecast_days_and_city
    entities:
    - city: "London"
    - days: 30
  - action: action_validate_city_info
  - action: action_validate_days_forecast
  - slot_was_set:
    - city: "London"
    - days: 30
  - action: utter_ask_for_shorter_forecast
  - intent: inform_days
  - action: action_validate_days_forecast
  - slot_was_set:
    - days: 7
    - city: "London"
  - action: action_get_future_weather_info
  - action: utter_show_possible_list_option

```

Rules.yml

```auto
version: "3.1"

rules:

- rule: Show help on session start
  steps:
  - action: action_session_start

- rule: Say goodbye anytime the user says goodbye
  steps:
    - intent: goodbye
    - action: utter_goodbye

- rule: Say 'I am a bot' anytime the user challenges
  steps:
    - intent: bot_challenge
    - action: utter_iamabot

- rule: Get weather information for valid city
  steps:
    - intent: request_current_weather_city
      entities:
        - city: "Berlin"
    - action: action_validate_city_info
    - slot_was_set:
        - city: "Berlin"
    - action: action_get_weather_info_current
    - action: utter_show_possible_list_option

- rule: Get weather information for invalid city
  steps:
    - intent: request_current_weather_city
      entities:
        - city: "abc"
    - action: action_validate_city_info
    - slot_was_set:
        - city: null
    - action: utter_request_city

- rule: Get weather information with ZIP code and country code
  steps:
    - intent: request_current_weather_zipcode_countrycode
      entities:
        - zipcode: "10001"
        - country_code: "US"
    - action: action_validate_zip_code_current_weather
    - action: action_validate_country_code_current_weather
    - slot_was_set:
        - zipcode: "10001"
        - country_code: "US"
    - action: action_get_zipcode_weather_current_weather
    - action: utter_show_possible_list_option

- rule: Handle missing end date for historical weather
  steps:
    - intent: request_historical_weather_daterange_city
      entities:
        - end_date: null
    - action: utter_ask_for_end_date

- rule: Handle missing start date for historical weather
  steps:
    - intent: request_historical_weather_daterange_city
      entities:
        - start_date: null
    - action: utter_ask_for_start_date

- rule: Ask the user to rephrase whenever they send a message with low NLU confidence
  steps:
    - intent: nlu_fallback
    - action: utter_please_rephrase

- rule: Handle core fallback
  steps:
    - action: action_default_fallback
    - action: utter_default

```

domain.yaml

```auto
version: "3.1"

intents:
  - greet
  - goodbye
  - affirm
  - deny
  - mood_great
  - mood_unhappy
  - bot_challenge
  - request_current_weather_city
  - request_current_weather_zipcode_countrycode
  - request_historical_weather_daterange_city
  - request_weather_forecast_timeperiod_and_city
  - request_weather_forecast_days_and_city
  - inform_city
  - inform_zipcode
  - inform_countrycode
  - inform_startdate
  - inform_enddate
  - inform_timeperiod
  - inform_days
  - nlu_fallback
  - ask_historical_weather
  - ask_severe_weather_alerts
  - ask_air_quality
  - ask_forecast
  - ask_current_weather
  - ask_for_help

entities:
  - city
  - time_period
  - input_validity
  - zipcode
  - country_code
  - start_date
  - end_date
  - days

slots:
  city:
    type: text
    influence_conversation: true
    mappings:
      - type: from_entity
        entity: city
      - type: from_text
        intent: request_current_weather_city

  time_period:
    type: text
    influence_conversation: true
    mappings:
      - type: from_entity
        entity: time_period
      - type: from_text
        intent: request_weather_forecast_timeperiod_and_city

  input_validity:
    type: categorical
    values:
      - valid
      - invalid
      - invalid_city
      - invalid_zipcode
      - invalid_days
      - invalid_daterange
      - incomplete_data
    influence_conversation: true
    mappings:
      - type: from_entity
        entity: input_validity

  zipcode:
    type: text
    influence_conversation: true
    mappings:
      - type: from_entity
        entity: zipcode
      - type: from_text
        intent: request_current_weather_zipcode_countrycode

  country_code:
    type: text
    influence_conversation: true
    mappings:
      - type: from_entity
        entity: country_code
      - type: from_text
        intent: request_current_weather_zipcode_countrycode

  start_date:
    type: text
    influence_conversation: true
    mappings:
      - type: from_entity
        entity: start_date
      - type: from_text
        intent: request_historical_weather_daterange_city

  end_date:
    type: text
    influence_conversation: true
    mappings:
      - type: from_entity
        entity: end_date
      - type: from_text
        intent: request_historical_weather_daterange_city

  days:
    type: text
    influence_conversation: true
    mappings:
      - type: from_entity
        entity: end_date
      - type: from_text
        intent: request_weather_forecast_days_and_city

responses:
  utter_greet:
    - text: "Hey! How can I assist you today? 🌟 I'm the Climia genius 🌈 weather bot! 🌞"
    - text: "Hello! Need help with the weather? I'm your Climia genius bot 🌟! 🌦️"
    - text: "Hi there! How can the Climia genius weather bot assist you today? 🌤️💬"

  utter_cheer_up:
    - text: "Here’s something to brighten your day! 🌟😊"
      image: "https://i.imgur.com/nGF1K8f.jpg"

  utter_did_that_help:
    - text: "Did that help? 🤔💡"

  utter_happy:
    - text: "Great! 🌼 I hope you have a fantastic day! 🌈"

  utter_goodbye:
    - text: "Take care and have a wonderful day! 👋🌟"

  utter_iamabot:
    - text: "I’m the Climia genius 🌟 weather bot 🤖, here to assist you with weather updates! 🌦️"

  utter_show_possible_list_option:
    - text: "✨ **Here are some options you can choose from:** ✨\n\n"
      buttons:
        - title: "🌦️ Check current weather"
          subtitle: "📝 **Required:** City"
          payload: "/request_current_weather_city"
        - title: "📍 Check current weather with zipcodes"
          subtitle: "📝 **Required:** Zip code & Country Code (2-letter)"
          payload: "/request_current_weather_zip"
        - title: "📅 Request historical weather"
          subtitle: "📝 **Required:** City, Start Date (YYYY-MM-DD), & End Date (YYYY-MM-DD) (Must be exactly 7 days or less)"
          payload: "/request_historical_weather"
        - title: "🔮 Request future weather forecast"
          subtitle: "📝 **Required:** City & Number of days(Max:15 days from today)"
          payload: "/request_future_weather"
        - title: "❓ Ask general questions"
          subtitle: "ℹ️ **No specific parameters needed**"
          payload: "/ask_general_questions"

  utter_request_city:
    - text: "Please enter the city you want to know the weather for. 🌆🌍"

  utter_please_rephrase:
    - text: "🤔 I didn't quite understand that. Could you rephrase? 📝"

  utter_default:
    - text: "🤖 Sorry, I didn't get that. Can you rephrase? 🔄"

  utter_ask_for_correct_countrycode:
    - text: "🚫 I couldn't find the provided country code 🌍. Please make sure you've entered a valid one. 🌏"

  utter_ask_for_correct_zipcode:
    - text: "🚫 I couldn't find the weather for the provided zip code 🗺️. Please make sure you've entered a valid one. 🌎"

  utter_ask_for_end_date:
    - text: "I am sorry. I could not find the provided end date. Please enter the end date for the historical weather data. 📅⏳"

  utter_ask_for_start_date:
    - text: "I am sorry. I could not find the provided start date. Please enter the start date for the historical weather data. 📅📆"

  utter_ask_for_correct_city:
    - text: "I am sorry. I could not find the provided city. Please enter the correct city 🌆🗺️"

  utter_invalid_daterange:
    - text: "🚫 The date range seems incorrect. Please ensure the start date is before the end date. 🗓️🔄"

  utter_ask_for_correct_daterange:
    - text: "📅 The date range is invalid. The start date should be earlier than the end date. Please correct it. 🕰️🛠️"

  utter_invalid_days:
    - text: "🕰️ The number of days you’ve entered is not valid. Please provide a number between 1 and 15. ❌"

  utter_ask_for_shorter_forecast:
    - text: "📉 Your forecast request exceeds the 15-day limit. Please specify a shorter time period. 🗓️"

  utter_invalid_timeperiod:
    - text: "🔄 The time period must be between 1 to 15 days. Please check and provide a valid duration. 🕰️🚫"

  utter_help:
    - text: "Here’s how you can use this bot:\n1. To get the current weather, ask about the weather in a specific city. 🌆🌦️\n2. For weather forecasts, mention the city and time period. 📅🔮\n3. To check historical weather data, provide the city and date range(YYYY-MM-DD). 📆📊\n4. For severe weather alerts, just ask if there are any alerts for your area. 🚨🌩️\n5. To get air quality information, specify the city. 🌬️📊\n6. You can change the temperature unit by asking for Celsius or Fahrenheit. 🌡️🔄"

  utter_ask_current_weather:
    - text: "To get the current weather, simply ask me about the weather in a specific city. For example, 'What’s the current weather in Tokyo?' 🌆🌤️"

  utter_ask_forecast:
    - text: "To get a weather forecast, ask for the weather in a city along with the time period you’re interested in. For example, 'Can you give me the weather forecast for New York for the next 7 days?' 📅🔮"

  utter_ask_historical_weather:
    - text: "To find historical weather data, ask for the weather in a city for a specific date range. For example, 'What was the weather like in London from 2024-01-01 to 2024-01-07(YYYY-MM-DD)?' 📆📊"

  utter_ask_severe_weather_alerts:
    - text: "To check for severe weather alerts, ask if there are any alerts for your area. For example, 'Are there any severe weather alerts for New York?' 🚨🌩️"

  utter_ask_air_quality:
    - text: "To get air quality information, ask for the air quality in a specific city. For example, 'What’s the air quality like in Berlin today?' 🌫️📊"

  utter_ask_temperature_unit:
    - text: "To change the temperature unit, ask for the temperature in Celsius or Fahrenheit. For example, 'Can I get the weather in Celsius?' 🌡️🔄"

actions:
  - action_default_fallback
  - utter_ask_for_correct_zipcode
  - utter_show_possible_list_option
  - utter_request_city
  - utter_ask_for_correct_countrycode
  - utter_please_rephrase
  - utter_default
  - utter_ask_for_end_date
  - utter_ask_for_start_date
  - utter_ask_for_correct_city
  - utter_invalid_daterange
  - utter_ask_for_correct_daterange
  - utter_ask_for_shorter_forecast
  - utter_invalid_timeperiod
  - utter_invalid_days
  - action_show_help_on_launch
  - action_session_start
  - action_validate_city_info
  - action_get_weather_info_current
  - action_validate_zip_code_current_weather
  - action_validate_country_code_current_weather
  - action_get_zipcode_weather_current_weather
  - action_validate_date_range_historical_weather
  - action_get_past_weather_info
  - action_validate_start_date
  - action_validate_end_date
  - action_validate_time_period_forecast
  - action_get_future_weather_info
  - action_validate_days_forecast

session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true

```

Can you please help me with stories and rules.yaml and domain.yaml to fix the contradicting stories ? I would appreciate the help , This is my error message

````auto
 InvalidRule: Contradicting rules or stories found 🚨

- the prediction of the action 'utter_ask_for_correct_zipcode' in story 'Handle invalid ZIP code input and correction' is contradicting with rule(s) 'Get weather information with ZIP code and country code' which predicted action 'action_get_zipcode_weather_current_weather'.
Please update your stories and rules so that they don't contradict each other.
You can find more information about the usage of rules at https://rasa.com/docs/rasa/rules. 
(weatherbot) trishachetani@TrishaChetanis-MacBook-Air weather %
``` I keep getting for all stories the same issue . how to tackle it
````

---

_[View the full topic](https://forum.rasa.com/t/how-to-deal-with-stories-and-rule-which-validate-negative-and-edge-cases/63035)._
