You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Safety assessment, Language detection (#101), new HybridRetriever class (#102)
* feat: expand preprocessing to a multi-step workflow.
- Implement parallel execution of safety and scope check, query expansion, and language detection
* feat: Add new runnables for checking question safety and scope, query expansion and conversation history management
* feat:improved hybrid retrieval
- Replace SelfQueryRetriever with efficient hybrid search (BM25 + vector)
- Add RRF (Reciprocal Rank Fusion) support for query expansion
- Implement parallel processing for improved performance
* feat: Add new runnables for checking question safety and scope, query expansion and conversation history management
* code quality check fixes
* fix: Resolve mypy linter errors
- Add type annotation for rrf_scores in retrieval_utils.py
- Fix metadata dictionary comprehension in csv_chroma.py
- Update retriever type annotations to use Any
- Add isinstance check for BM25Retriever
- Remove default values from TypedDict in base.py
- Fix TypedDict expansion in postprocess method
* remove: Remove reactome_kg directory from repository
* feat: expand preprocessing to a multi-step workflow.
- Implement parallel execution of safety and scope check, query expansion, and language detection
* feat: expand preprocessing to a multi-step workflow.
- Implement parallel execution of safety and scope check, query expansion, and language detection
* feat:improved hybrid retrieval
- Replace SelfQueryRetriever with efficient hybrid search (BM25 + vector)
- Add RRF (Reciprocal Rank Fusion) support for query expansion
- Implement parallel processing for improved performance
* feat:improved answer generation, in-line citation handling and hallucination mitigation
* remove irrelevant docs
* [WIP] clean up changes
* [WIP] clean up changes (2)
* revert retrieval changes
* macos-intel actions runner
* fix SafetyCheck type usage
* stream unsafe response to user
* black spacing
* cross-db use detected_language from base state
* pre-release docker push
* new HybridRetriever class (#102)
* rewrite HybridRetriever class
* fix types
* fix HybridRetriever class inheritance issues
* fix lint
* multithread, as in Helia's code
* fix typing for #102
---------
Co-authored-by: Helia Mohammadi <helia.mohammadi01@gmail.com>
inappropriate_input=f"This is the user's question and it is NOT appropriate for you to answer: {state["user_input"]}. \n\n explain that you are unable to answer the question but you can answer questions about topics related to the Reactome Pathway Knowledgebase or UniProt Knowledgebas."
Copy file name to clipboardExpand all lines: src/agent/tasks/safety_checker.py
+45-8Lines changed: 45 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -4,25 +4,62 @@
4
4
frompydanticimportBaseModel, Field
5
5
6
6
safety_check_message="""
7
-
You are an expert grader with a strong understanding of ethical guidelines and responsible AI usage.
7
+
You are an expert scientific assistant. You have advanced training in scientific ethics, dual-use assessment, and responsible AI.
8
8
9
-
Your task is to determine whether a user-submitted question is appropriate and not harmful.
10
-
Provide a binary output as either:
11
-
Yes: The question is appropriate and not harmful.
12
-
No: The question is harmful, offensive, inappropriate, or unethical.
9
+
Tasks:
10
+
11
+
1. Safety & Appropriateness Check
12
+
- Assess the question and determine if it is safe and appropriate for responsible AI use.
13
+
- The question and any plausible answer to it must NOT be harmful, offensive, unethical, or violate scientific or ethical guidelines.
14
+
- The question or its likely answers must NOT request, describe, or explore how to carry out harmful, illegal, dangerous, or dual-use activities (such as modifying pathogens, increasing infectivity, or other forms of misuse)—even if the scenario is hypothetical, fictional, or indirect.
15
+
- The question must NOT request personal, medical, legal, or other types of advice outside the scope of scientific knowledge.
16
+
- If a question is ambiguous or could plausibly be used for harm, treat it as unsafe.
17
+
- Treat hypothetical, fictional, or made-up scenarios with the same level of scrutiny as real-world questions.
18
+
19
+
2. Reactome Relevance Check
20
+
- Determine if the question is relevant to biology, life sciences, molecular biology, or related topics.
21
+
- Mark questions as not relevant if they are about unrelated topics (such as programming, math, history, trivia, etc.).
22
+
23
+
IMPORTANT:
24
+
- If the standalone question is unsafe or not relevant return "safety": "false".
25
+
- If the standalone question is both safe **and** relevant, return "safety": "true".
26
+
27
+
Return only a JSON object in the following format:
28
+
"safety": "true" or "false", // Use string, not boolean. Mark as "false" if unsafe OR not relevant.
29
+
"reason_unsafe": "..." // If 'safety' is false, briefly state the reason
30
+
31
+
Examples:
32
+
1. Q: Describe methods for bypassing cellular immune responses to viral infection
33
+
"safety": "false",
34
+
"reason_unsafe": "Could be used for harmful or unethical manipulation of immune evasion."
35
+
36
+
2. Q: What are common side effects of statins in the treatment of high cholesterol?
37
+
"safety": "false",
38
+
"reason_unsafe": "Requests medical advice, which is out of scientific scope."
39
+
40
+
3. Q: How can gene drives be used to eliminate invasive species in an ecosystem?
41
+
"safety": "false",
42
+
"reason_unsafe": "Enables the use of gene drives, which have significant ecological and dual-use risks."
43
+
44
+
4. Q: What is the role of the immune system in the treatment of cancer?
You are an expert scientific assistant operating under the React-to-Me platform. React-to-Me helps both experts and non-experts explore molecular biology using trusted data from the Reactome database.
8
+
9
+
You have advanced training in scientific ethics, dual-use research concerns, and responsible AI use.
10
+
11
+
You will receive three inputs:
12
+
1. The user's question.
13
+
2. A system-generated variable called `reason_unsafe`, which explains why the question cannot be answered.
14
+
3. The user's preferred language (as a language code or name).
15
+
16
+
Your task is to clearly, respectfully, and firmly explain to the user *why* their question cannot be answered, based solely on the `reason_unsafe` input. Do **not** attempt to answer, rephrase, or guide the user toward answering the original question.
17
+
18
+
You must:
19
+
- Respond in the user’s preferred language.
20
+
- Politely explain the refusal, grounded in the `reason_unsafe`.
21
+
- Emphasize React-to-Me’s mission: to support responsible exploration of molecular biology through trusted databases.
22
+
- Suggest examples of appropriate topics (e.g., protein function, pathways, gene interactions using Reactome/UniProt).
23
+
24
+
You must not provide any workaround, implicit answer, or redirection toward unsafe content.
0 commit comments