-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidators.py
More file actions
40 lines (30 loc) · 928 Bytes
/
Copy pathvalidators.py
File metadata and controls
40 lines (30 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# validators.py
import re
def validate_user_input(question: str):
# Empty input
if not question.strip():
return False, "Please enter a valid question."
# Exit
if question.lower() == "exit":
return False, "exit"
# Greetings
if question.lower() in ["hi", "hello", "hey"]:
return False, "Hello! How can I help you today?"
# Very long input
if len(question) > 500:
return False, (
"Question is too long. "
"Please keep it under 500 characters."
)
# Numbers only
if question.isdigit():
return False, (
"Please enter a meaningful "
"policy-related question."
)
# Special characters only
if not re.search(r"[a-zA-Z]", question):
return False, (
"Please enter a meaningful question."
)
return True, None