Skip to content

Commit 8b2bd7a

Browse files
CHANGED ANSWER FORMULATION PROMPT TO BE STRICTER
1 parent e9da1fb commit 8b2bd7a

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed
Binary file not shown.

FASTAPI-DEPLOYMENT/rhl_fastapi_v2_modify.py

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,13 @@ async def _background_update_and_save(user_id: str, user_message: str, bot_reply
591591
- Summarize meaningfully in a perfect flow
592592
- Do NOT mention references to what's not-there in the context (e.g., "the document doesn't have much info about X" ❌)
593593
594-
STEP 1 - FILTERING:
594+
STEP 1 - FILTERING (CRITICAL):
595595
- Evaluate each context chunk individually
596-
- Use only chunks that contain information relevant to answering the query
597-
- Ignore chunks that don't address the query topic
598-
- If a chunk has partial but relevant information, include it
596+
- Use ONLY chunks that DIRECTLY answer what is asked in the query
597+
- A chunk directly answers if it contains information that specifically addresses the question
598+
- If a chunk mentions related topics but doesn't answer the specific question → EXCLUDE it
599+
- If NO chunks directly answer the query → Return: "I couldn't find sufficient information in the provided documents to answer this question accurately."
600+
- DO NOT list facts about topics mentioned in context if they don't answer the query
599601
600602
STEP 2 - MULTI-SOURCE CONSOLIDATION (CRITICAL):
601603
When multiple sources contain information about the same topic:
@@ -760,6 +762,50 @@ async def _background_update_and_save(user_id: str, user_message: str, bot_reply
760762
761763
---
762764
765+
Example 6 - When Context Doesn't Answer Query (CRITICAL):
766+
767+
❌ Query: "Is magnesium sulfate recommended for jaundice treatment?"
768+
Context mentions:
769+
- "Magnesium sulfate is used for pre-eclampsia prevention..."
770+
- "Jaundice treatment involves phototherapy..."
771+
772+
Analysis: Context mentions BOTH topics separately but doesn't connect them. No information about magnesium sulfate for jaundice.
773+
Answer: "I couldn't find sufficient information in the provided documents to answer this question accurately."
774+
775+
❌ Query: "What causes fever?"
776+
Context: "Headache symptoms include pain, pressure, and sensitivity to light..."
777+
778+
Analysis: Context is about headache, not fever. Wrong topic entirely.
779+
Answer: "I couldn't find sufficient information in the provided documents to answer this question accurately."
780+
781+
❌ Query: "How to treat dehydration?"
782+
Context: "Dehydration prevention involves drinking water regularly..."
783+
784+
Analysis: Context is about prevention, not treatment. Doesn't answer what was asked.
785+
Answer: "I couldn't find sufficient information in the provided documents to answer this question accurately."
786+
787+
❌ Query: "What are the symptoms of jaundice?"
788+
Context: "Magnesium sulfate dosing involves 4g IV loading dose..."
789+
790+
Analysis: Context is about magnesium sulfate dosing, not jaundice symptoms. Completely unrelated.
791+
Answer: "I couldn't find sufficient information in the provided documents to answer this question accurately."
792+
793+
✅ Query: "What causes fever?"
794+
Context: "Fever is caused by infections, inflammatory conditions, and certain medications..."
795+
796+
Analysis: Context directly answers the question about fever causes.
797+
Answer: [Normal answer generation with facts about fever causes]
798+
799+
✅ Query: "Is magnesium sulfate recommended for pre-eclampsia?"
800+
Context: "Magnesium sulfate is recommended for pre-eclampsia prevention..."
801+
802+
Analysis: Context directly connects magnesium sulfate to pre-eclampsia.
803+
Answer: [Normal answer generation]
804+
805+
CRITICAL RULE: If you cannot find information that DIRECTLY answers the query in the context, you MUST respond with: "I couldn't find sufficient information in the provided documents to answer this question accurately." Do NOT list unrelated facts just because the topics are mentioned in the context.
806+
807+
---
808+
763809
WORD LIMIT AND STRUCTURE:
764810
- STRICTLY 150-200 words total
765811
- Use 4-5 bullet points if sufficient information is available
@@ -820,7 +866,11 @@ async def _background_update_and_save(user_id: str, user_message: str, bot_reply
820866
- Example: "Would you like to know about jaundice treatment?" (not "Would you like more information?")
821867
- The follow-up question should be the LAST line of your response
822868
823-
IMPORTANT: If chunks in <context> seem partially relevant or borderline, still use them - your role is to judge and extract useful information. Only exclude chunks that are completely unrelated to the query.
869+
IMPORTANT:
870+
- Only use chunks that DIRECTLY answer what is asked in the query
871+
- If chunks mention related topics but don't answer the specific question → EXCLUDE them
872+
- If NO chunks directly answer the query → Respond with: "I couldn't find sufficient information in the provided documents to answer this question accurately."
873+
- DO NOT provide information about topics mentioned in context if they don't answer the query
824874
825875
REMINDER: If <followup_context> is provided, you MUST generate a follow-up question. Do not skip this step.
826876
0 Bytes
Binary file not shown.

chat_history.db

184 KB
Binary file not shown.

0 commit comments

Comments
 (0)