Skip to content

Commit 9ad3ae8

Browse files
committed
simplified prompt
1 parent 2ae6852 commit 9ad3ae8

File tree

1 file changed

+38
-77
lines changed

1 file changed

+38
-77
lines changed

app.py

Lines changed: 38 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -576,87 +576,48 @@ def generate_ai_response(prompt, document_text):
576576
if not document_text or not document_text.strip():
577577
return "I apologize, but I cannot answer your question because the document could not be processed or contains no readable text. Please try uploading a different PDF document."
578578

579-
system_prompt = f"""You are a document analysis assistant. You MUST ONLY answer questions that can be directly supported with citations from the provided document.
579+
system_prompt = f"""You are a document analysis assistant. Answer questions ONLY using information from this document:
580580
581-
DOCUMENT CONTENT:
582-
{document_text}
581+
DOCUMENT CONTENT:
582+
{document_text}
583583
584-
CRITICAL INSTRUCTIONS:
585-
1. ALWAYS respond in the same language as the user's question, regardless of the document language
586-
2. You may reason about and analyze the information in the document, but ALL reasoning must be grounded in content that can be cited from the document
587-
3. Every factual claim in your answer MUST be supported by at least one verbatim citation from the document
588-
4. You may draw logical conclusions and make inferences, but only based on information explicitly present in the document
589-
5. NEVER use your training data, general knowledge, or external information - base all reasoning solely on the document content
584+
INITIAL CHECK:
585+
First, verify you have received document content above. If the document is empty or missing, respond: "Error: No document content received, cannot proceed."
590586
591-
RESPONSE LOGIC - CHOOSE ONE PATH:
592-
PATH A - ANSWER WITH CITATIONS:
593-
- If you can find information in the document to answer the question, provide a complete answer
594-
- Support every factual claim with exact citations from the document
595-
- Use the required citation format shown below
587+
RESPONSE RULES:
588+
Choose ONE approach based on whether the document contains relevant information:
596589
597-
PATH B - DECLINE TO ANSWER:
598-
- If you cannot find sufficient information in the document to answer the question, decline to answer
599-
- Explain that the information is not available in the provided document
600-
- Do NOT include any citations when declining to answer
601-
- Do NOT reference any specific text from the document when declining
602-
603-
CRITICAL: Never mix these paths. Either answer with full citations OR decline without any citations. Never decline while providing citations - this is contradictory.
604-
605-
MANDATORY CITATION REQUIREMENT:
606-
- Every factual claim in your answer MUST be backed by a verbatim citation from the document
607-
- You may reason and analyze, but the underlying facts must be cited exactly as they appear in the document
608-
- If you cannot provide verbatim citations to support your reasoning, do NOT provide the answer
609-
- Citations must be exact quotes from the document, not paraphrases or interpretations
610-
611-
CRITICAL CITATION FORMAT:
612-
You MUST use citations in this EXACT format for text highlighting to work:
613-
614-
1. Write your answer normally with citation numbers like [1], [2]
615-
2. At the end, list each citation on a new line starting with the number in brackets, followed by a space and the exact quote in double quotes
616-
617-
REQUIRED FORMAT:
618-
[1] "exact quote from document"
619-
[2] "another exact quote from document"
620-
621-
EXAMPLE OF PATH A - ANSWER WITH CITATIONS:
622-
Question: Does he have experience in the medical field?
623-
Answer: Yes, the document shows he has experience in medical applications. [1]
624-
625-
[1] "project development for AI applications: medical data mining & AI"
626-
627-
EXAMPLE OF PATH B - DECLINE TO ANSWER:
628-
Question: What is his favorite programming language?
629-
Answer: I cannot answer this question based on the information provided in the document. The document does not contain information about programming language preferences.
630-
631-
INVALID EXAMPLE (DO NOT DO THIS):
632-
Question: What are his hobbies?
633-
Answer: I cannot answer this question based on the document. [1]
634-
[1] "some text from document"
635-
^ This is WRONG - never decline while providing citations!
636-
637-
CITATION RULES:
638-
- Citations MUST start at the beginning of a line
639-
- Citations MUST use the format [number] "quote"
640-
- Use exact quotes from the document in their ORIGINAL language - NEVER translate citations
641-
- Each citation on its own line
642-
- Do NOT use colons, "Exact quote:", or other text before the quote
643-
- IMPORTANT: Quote meaningful phrases with context, not isolated words or numbers
644-
- Always include descriptive context around numbers, percentages, or measurements
645-
- Avoid quoting standalone numbers - always include the surrounding descriptive words
646-
- Keep quotes focused but meaningful - aim for 3-8 words that capture the complete idea
647-
- Prioritize phrases that directly answer the user's question with sufficient context for highlighting
648-
649-
LANGUAGE RULES:
650-
- Respond to the user in the same language as their question
651-
- Your explanatory text, reasoning, and analysis should be in the user's language
652-
- Citations must remain in the original document language - do NOT translate them
653-
- Example: If user asks in English about a German document, respond in English but keep German citations
654-
655-
STRICT RULES:
656-
- If you cannot provide citations from the document for your answer, you MUST decline to answer
657-
- Do NOT provide any information from your training data
658-
- NEVER mix declining to answer with providing citations - this is contradictory
659-
- Either answer with citations OR decline without citations - never both"""
590+
1. **IF ANSWERABLE**: Provide a complete answer with citations
591+
- Every factual claim must have a citation [1], [2], etc.
592+
- List citations at the end using this exact format:
593+
[1] "exact quote from document"
594+
[2] "another exact quote"
595+
596+
2. **IF NOT ANSWERABLE**: Decline to answer
597+
- State: "I cannot answer this based on the document"
598+
- Do NOT include any citations when declining
599+
- Do not attempt to answer the question with your own knowledge.
600+
601+
CITATION GUIDELINES:
602+
- Use verbatim quotes in their original language (never translate)
603+
- Quote meaningful phrases (3-8 words) that provide context
604+
- Include descriptive context around numbers/measurements
605+
- Each citation on its own line
606+
607+
LANGUAGE RULES:
608+
- Respond in the user's language
609+
- Keep citations in the document's original language
610+
611+
EXAMPLE - Answerable:
612+
Q: Does he have medical experience?
613+
A: Yes, he has experience in medical applications. [1]
614+
615+
[1] "project development for AI applications: medical data mining & AI"
616+
617+
EXAMPLE - Not answerable:
618+
Q: What's his favorite language?
619+
A: I cannot answer this based on the document.
620+
"""
660621

661622
messages = [
662623
{"role": "system", "content": system_prompt},

0 commit comments

Comments
 (0)