{"record":{"id":"6da4caa3f977c7ca","repo":"Textualize/rich","slug":"prompt-invalid-please-enter-a-valid-value","errorCode":null,"errorMessage":"[prompt.invalid]Please enter a valid value","messagePattern":"\\[prompt\\.invalid\\]Please enter a valid value","errorType":"console","errorClass":"InvalidResponse","httpStatus":null,"severity":"warning","filePath":"rich/prompt.py","lineNumber":243,"sourceCode":"        return value.strip().lower() in [choice.lower() for choice in self.choices]\n\n    def process_response(self, value: str) -> PromptType:\n        \"\"\"Process response from user, convert to prompt type.\n\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:","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/Textualize/rich/blob/9d8f9a372cc5916fd4781fec207ced7ddac2f08f/rich/prompt.py#L225-L261","documentation":"Prompt.process_response() converts the user's typed string via self.response_type (e.g. int for IntPrompt). If that constructor raises ValueError — the input can't be parsed — rich raises InvalidResponse with validate_error_message ('[prompt.invalid]Please enter a valid value'). It is an internal control-flow exception caught by the ask loop, which re-prompts; it only escapes if you call process_response directly.","triggerScenarios":"IntPrompt.ask('Enter a number') and the user types 'abc'; Prompt(response_type=int) with non-numeric input; calling prompt.process_response('not-an-int') outside the ask loop. Any response_type whose constructor raises ValueError on the raw string.","commonSituations":"Interactive CLIs validated with IntPrompt/FloatPrompt where users paste text or leave stray characters; overriding process_response or calling it directly (bypassing ask's retry loop); a custom response_type with a constructor that raises ValueError for valid-looking input.","solutions":["Rely on Prompt.ask/IntPrompt.ask — the built-in loop catches InvalidResponse and re-prompts automatically; no action needed.","If calling process_response yourself, wrap it in try/except InvalidResponse and loop until valid.","For custom response_type, ensure its constructor raises ValueError (the only type caught) on bad input, or override process_response."],"exampleFix":"# before\nvalue = prompt.process_response(raw)  # InvalidResponse escapes\n\n# after\nfrom rich.prompt import InvalidResponse\nwhile True:\n    try:\n        value = prompt.process_response(input('> '))\n        break\n    except InvalidResponse:\n        print('try again')","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from rich.prompt import InvalidResponse, IntPrompt\n# ask() already retries; only needed for direct process_response:\ntry:\n    val = IntPrompt.process_response(prompt, raw)\nexcept InvalidResponse:\n    val = None  # re-ask","preventionTips":["Use the .ask() classmethod loop rather than calling process_response directly.","Give users a default= so empty input resolves instead of failing repeatedly.","Custom response_type must raise ValueError on bad input for the retry loop to catch it."],"tags":["rich","prompt","validation","user-input","cli"],"backgroundTag":null,"analyzedSha":"9d8f9a372cc5916fd4781fec207ced7ddac2f08f","analyzedAt":"2026-08-15T03:30:11.781Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}