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

Stories.yml

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

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

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

 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