{"record":{"id":"ecb4988c8cc15dba","repo":"Textualize/rich","slug":"prompt-invalid-choice-please-select-one-of-the-av","errorCode":null,"errorMessage":"[prompt.invalid.choice]Please select one of the available options","messagePattern":"\\[prompt\\.invalid\\.choice\\]Please select one of the available options","errorType":"console","errorClass":"InvalidResponse","httpStatus":null,"severity":"warning","filePath":"rich/prompt.py","lineNumber":247,"sourceCode":"\n        Args:\n            value (str): String typed by user.\n\n        Raises:\n            InvalidResponse: If ``value`` is invalid.\n\n        Returns:\n            PromptType: The value to be returned from ask method.\n        \"\"\"\n        value = value.strip()\n        try:\n            return_value: PromptType = self.response_type(value)\n        except ValueError:\n            raise InvalidResponse(self.validate_error_message)\n\n        if self.choices is not None:\n            if not self.check_choice(value):\n                raise InvalidResponse(self.illegal_choice_message)\n\n            if not self.case_sensitive:\n                # return the original choice, not the lower case version\n                return_value = self.response_type(\n                    self.choices[\n                        [choice.lower() for choice in self.choices].index(value.lower())\n                    ]\n                )\n        return return_value\n\n    def on_validate_error(self, value: str, error: InvalidResponse) -> None:\n        \"\"\"Called to handle validation error.\n\n        Args:\n            value (str): String entered by user.\n            error (InvalidResponse): Exception instance the initiated the error.\n        \"\"\"\n        self.console.print(error, markup=True)","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/Textualize/rich/blob/9d8f9a372cc5916fd4781fec207ced7ddac2f08f/rich/prompt.py#L229-L265","documentation":"When a Prompt has choices= set, process_response() calls check_choice(value); if the (case-adjusted) input is not among the choices it raises InvalidResponse with illegal_choice_message ('[prompt.invalid.choice]Please select one of the available options'). Like other prompt errors it is caught by ask(), which re-displays the prompt; it surfaces only when process_response is called outside that loop.","triggerScenarios":"Prompt.ask('Proceed', choices=['yes','no','abort']) and the user types 'maybe'; case-sensitive prompt where the user types 'YES' but the choice is 'yes' with case_sensitive=True; calling process_response('bogus') directly.","commonSituations":"Menu-driven CLIs where users type free text not in the list; forgetting that case_sensitive defaults to True for Prompt (so 'Y' fails against choice 'y'); typos in choice matching when choices are generated dynamically and the offered list differs from choices=.","solutions":["Use Prompt.ask(..., choices=[...]) so rich re-prompts on invalid choice automatically.","Pass case_sensitive=False to accept 'YES'/'Yes' for choice 'yes'.","If you call process_response yourself, catch InvalidResponse and loop; or pre-check with prompt.check_choice(value)."],"exampleFix":"# before\nans = Prompt.ask('Mode', choices=['auto','manual'], case_sensitive=True)\n# user types 'AUTO' -> re-prompt / InvalidResponse if called directly\n\n# after\nans = Prompt.ask('Mode', choices=['auto','manual'], case_sensitive=False)","handlingStrategy":"validation","validationCode":"from rich.prompt import Prompt\nchoices = ['auto', 'manual']\nraw = input('> ')\nif not Prompt(f'{\"mode\"}', choices=choices, case_sensitive=False).check_choice(raw):\n    raw = choices[0]  # fallback","typeGuard":null,"tryCatchPattern":"try:\n    p.process_response(raw)\nexcept InvalidResponse as e:\n    # show e.text and re-prompt\n    ...","preventionTips":["Pre-check membership with prompt.check_choice(value) when driving stdin programmatically.","Set case_sensitive=False when users may vary capitalization.","Keep the displayed options list identical to choices=."],"tags":["rich","prompt","choices","user-input","cli"],"backgroundTag":null,"analyzedSha":"9d8f9a372cc5916fd4781fec207ced7ddac2f08f","analyzedAt":"2026-08-15T03:30:11.781Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}