def loop_until_choice_is_correct(msg_prompt: str, valid_choices: dict) -> str:
    """
    Loop until a valid value is provided, which must match a key from
    `valid_choices`.

    Args:
        msg_prompt (str): Prompt to display to the user to enter a choice.
        valid_choices (dict, optional): Keys are valid choices.

    Returns:
        str: String corresponding to the value of the matching key in
        `valid_choice`.
    """
    choice = None
    while True:
        input_string = input(f"{msg_prompt}: ")
        if input_string not in valid_choices:
            print("Please enter a valid choice.")
        else:
            choice = valid_choices[input_string]
            break

    return choice