diff --git a/changelog/4795.feature.rst b/changelog/4795.feature.rst new file mode 100644 index 000000000000..ae7e183a3cf1 --- /dev/null +++ b/changelog/4795.feature.rst @@ -0,0 +1 @@ +Replaced the warnings about missing templates, intents etc. in validator.py by debug messages. diff --git a/docs/user-guide/validate-files.rst b/docs/user-guide/validate-files.rst index 90a07c03a882..a8e732e1498f 100644 --- a/docs/user-guide/validate-files.rst +++ b/docs/user-guide/validate-files.rst @@ -23,6 +23,11 @@ the script: .. program-output:: rasa data validate --help +By default the validator searches only for errors in the data (e.g. the same +example being listed as an example for two intents), but does not report other +minor issues (such as unused intents, utterances that are not listed as +actions). To also report the later use the ``-debug`` flag. + You can also run these validations through the Python API by importing the `Validator` class, which has the following methods: diff --git a/rasa/core/events/__init__.py b/rasa/core/events/__init__.py index 212bd28ab773..d88057092683 100644 --- a/rasa/core/events/__init__.py +++ b/rasa/core/events/__init__.py @@ -144,10 +144,7 @@ def _from_story_string(cls, parameters: Dict[Text, Any]) -> Optional[List["Event return [cls(parameters.get("timestamp"), parameters.get("metadata"))] def as_dict(self) -> Dict[Text, Any]: - d = { - "event": self.type_name, - "timestamp": self.timestamp, - } + d = {"event": self.type_name, "timestamp": self.timestamp} if self.metadata: d["metadata"] = self.metadata diff --git a/rasa/core/validator.py b/rasa/core/validator.py index b866b34cd2e8..c6463df8aa4e 100644 --- a/rasa/core/validator.py +++ b/rasa/core/validator.py @@ -43,9 +43,9 @@ def verify_intents(self, ignore_warnings: bool = True) -> bool: for intent in self.domain.intents: if intent not in nlu_data_intents: - warnings.warn( + logger.debug( f"The intent '{intent}' is listed in the domain file, but " - "is not found in the NLU training data." + f"is not found in the NLU training data." ) everything_is_alright = ignore_warnings and everything_is_alright @@ -53,7 +53,8 @@ def verify_intents(self, ignore_warnings: bool = True) -> bool: if intent not in self.domain.intents: warnings.warn( f"The intent '{intent}' is in the NLU training data, but " - f"is not listed in the domain." + f"is not listed in the domain.", + stacklevel=2, ) everything_is_alright = False @@ -77,7 +78,9 @@ def verify_example_repetition_in_intents( everything_is_alright = ignore_warnings and everything_is_alright intents_string = ", ".join(sorted(intents)) warnings.warn( - f"The example '{text}' was found in these multiples intents: {intents_string }" + f"The example '{text}' was found in multiple intents: " + f"{intents_string}.", + stacklevel=2, ) return everything_is_alright @@ -100,13 +103,14 @@ def verify_intents_in_stories(self, ignore_warnings: bool = True) -> bool: if story_intent not in self.domain.intents: warnings.warn( f"The intent '{story_intent}' is used in stories, but is not " - f"listed in the domain file." + f"listed in the domain file.", + stacklevel=2, ) everything_is_alright = False for intent in self.domain.intents: if intent not in stories_intents: - warnings.warn(f"The intent '{intent}' is not used in any story.") + logger.debug(f"The intent '{intent}' is not used in any story.") everything_is_alright = ignore_warnings and everything_is_alright return everything_is_alright @@ -128,16 +132,18 @@ def verify_utterances(self, ignore_warnings: bool = True) -> bool: for utterance in utterance_templates: if utterance not in actions: - warnings.warn( + logger.debug( f"The utterance '{utterance}' is not listed under 'actions' in the " - "domain file. It can only be used as a template." + f"domain file. It can only be used as a template." ) everything_is_alright = ignore_warnings and everything_is_alright for action in actions: if action.startswith(UTTER_PREFIX): if action not in utterance_templates: - warnings.warn(f"There is no template for utterance '{action}'.") + warnings.warn( + f"There is no template for utterance '{action}'.", stacklevel=2 + ) everything_is_alright = False return everything_is_alright @@ -168,14 +174,15 @@ def verify_utterances_in_stories(self, ignore_warnings: bool = True) -> bool: if event.action_name not in utterance_actions: warnings.warn( f"The utterance '{event.action_name}' is used in stories, but is not a " - f"valid utterance." + f"valid utterance.", + stacklevel=2, ) everything_is_alright = False stories_utterances.add(event.action_name) for utterance in utterance_actions: if utterance not in stories_utterances: - warnings.warn(f"The utterance '{utterance}' is not used in any story.") + logger.debug(f"The utterance '{utterance}' is not used in any story.") everything_is_alright = ignore_warnings and everything_is_alright return everything_is_alright diff --git a/tests/core/test_validator.py b/tests/core/test_validator.py index 4e098fbdfd13..f9ccc6b77fb2 100644 --- a/tests/core/test_validator.py +++ b/tests/core/test_validator.py @@ -82,8 +82,8 @@ async def test_verify_logging_message_for_repetition_in_intents(caplog): validator.verify_example_repetition_in_intents(False) assert len(record) == 1 assert ( - "The example 'good afternoon' was found in these " - "multiples intents: goodbye, greet" in record[0].message.args[0] + "The example 'good afternoon' was found in " + "multiple intents: goodbye, greet" in record[0].message.args[0] )