def parse_text_matching_options(valid_options):
    """
    Create a function to validate a string against choices

    Args:
        valid_options (list of str): Valid options for the text
    """

    def validate(text):
        """
        Verify that the string matches one of the options, or else raise an exception

        Args:
            text (str): Some text
        """
        if text not in valid_options:
            raise Exception(
                f"Unexpected option {text}. Valid options: {', '.join(valid_options)}"
            )
        return text

    return validate