Basitha commited on
Commit
b067ae5
·
verified ·
1 Parent(s): 781c26a

changes to question validation

Browse files
researchsimulation/InteractiveInterviewChatbot.py CHANGED
@@ -132,9 +132,9 @@ def validate_question_topics(parsed_questions, processor_llm):
132
  ### Question:
133
  {question}
134
  ### Permitted Topics Scope:
135
- The respondents may only answer questions related to the following general topics:
136
 
137
- - Demographics: Age, location, education, family background, life events.
138
  - Values & Beliefs: Family responsibility, independence, hard work, gender equality, spirituality, simplicity, mental health, traditional vs modern values.
139
  - Career & Aspirations: Education, career goals, entrepreneurship, financial independence, stability, ambition, and personal development.
140
  - Influences & Role Models: Family members, mentors, public figures, influencers.
@@ -148,29 +148,24 @@ def validate_question_topics(parsed_questions, processor_llm):
148
  - Personal Growth & Development: Maturity, emotional regulation, responsibility, adaptability, self-improvement, learning mindset.
149
 
150
  ### Validation Instructions:
151
- You must determine if the question is appropriate for a lifestyle, values, and personal development interview.
152
 
153
- 1. **Topical Relevance**
154
- - Accept the question only if it is **clearly relevant** to the Permitted Topics Scope and can be answered from a **personal, lifestyle, or values-based perspective**.
 
 
 
155
 
156
- 2. **Content Restrictions**
157
- Return exactly "INVALID" if the question contains any of the following:
158
- - Hate speech, discrimination, harassment
159
- - Sexually explicit, violent, or graphic content
160
- - Religious extremism or proselytising
161
- - Politically sensitive content:
162
- - Opinions or knowledge about politicians or political parties
163
- - Policy debates, election-related topics, or partisan comparisons
164
- - References to extremist ideologies or hate groups
165
- - Overly technical, academic, or scientific content not grounded in personal lifestyle (e.g. biology, physics, finance, geopolitics)
166
- - News-related or controversial current events
167
 
168
- 3. **Everyday Relevance**
169
- - Even if the topic superficially fits the scope, it must be **personally relatable, non-controversial**, and answerable by someone with the respondent's **general life experience**, not specialised knowledge.
170
 
171
- 4. **Output Instructions**
172
- - If invalid, return exactly: "INVALID"
173
- - If valid, return the **same question**
174
 
175
  ### Output:
176
  <Validated question OR "INVALID">
@@ -424,8 +419,8 @@ def validate_tailored_answer(agent_name, agent_question, respondent_agent, tailo
424
  logging.info(f"[validate_tailored_answer] Validation result for attempt {attempt+1}: {is_valid}")
425
 
426
  if is_valid:
427
- if len(tailored_answer) > 800:
428
- logging.warning(f"Tailored answer exceeds 800 characters (length={len(tailored_answer)}); retrying...")
429
  attempt += 1
430
  else:
431
  validated = True
 
132
  ### Question:
133
  {question}
134
  ### Permitted Topics Scope:
135
+ The chatbot is designed to explore personal views, habits, and life experiences. The following topics are allowed:
136
 
137
+ - Demographics: Age, name, location, education, family background, life events.
138
  - Values & Beliefs: Family responsibility, independence, hard work, gender equality, spirituality, simplicity, mental health, traditional vs modern values.
139
  - Career & Aspirations: Education, career goals, entrepreneurship, financial independence, stability, ambition, and personal development.
140
  - Influences & Role Models: Family members, mentors, public figures, influencers.
 
148
  - Personal Growth & Development: Maturity, emotional regulation, responsibility, adaptability, self-improvement, learning mindset.
149
 
150
  ### Validation Instructions:
 
151
 
152
+ 1. **Accept the question** if:
153
+ - It fits naturally into a friendly, personal conversation.
154
+ - It relates to one of the permitted topic areas *OR* is a simple, personal background question (e.g. name, where you live, age).
155
+ - It can be answered from a **personal lifestyle, identity, or values-based** perspective — including light or introductory prompts.
156
+ - It helps the chatbot get to know the respondent (even if it's informal or simple).
157
 
158
+ 2. **Reject the question** by returning **"INVALID"** if it includes:
159
+ - Hate speech, abuse, discrimination
160
+ - Sexual, violent, or explicit content
161
+ - Religious proselytising or extremism
162
+ - Political content (politicians, parties, policies, elections)
163
+ - Technical, academic, or scientific topics unrelated to lifestyle
164
+ - News, current events, or controversial debates
 
 
 
 
165
 
166
+ 3. **If the question is valid**, return the same question rewritten using **British English spelling and phrasing** (keep the meaning unchanged, use natural conversational style).
 
167
 
168
+ 4. **If invalid**, return **only**: "INVALID"
 
 
169
 
170
  ### Output:
171
  <Validated question OR "INVALID">
 
419
  logging.info(f"[validate_tailored_answer] Validation result for attempt {attempt+1}: {is_valid}")
420
 
421
  if is_valid:
422
+ if len(tailored_answer) > 1000:
423
+ logging.warning(f"Tailored answer exceeds 1000 characters (length={len(tailored_answer)}); retrying...")
424
  attempt += 1
425
  else:
426
  validated = True