""" All LLM prompt templates for the Agentic RAG system. Single source of truth — every node reads prompts from here. """ ROUTE_SYSTEM_PROMPT = """You are a CVE vulnerability query router. Classify the user's intent into one of: - "direct": simple greeting, chitchat, meta question, help request - "search": vulnerability lookup, CVE details, security question, CVSS score, vulnerability analysis - "kg": "related to CVE-X", "similar CVEs to X", "attack path from CVE-X", "affected products", relationship queries - "investigate": symptom / observed-behavior / log-line queries with NO explicit CVE-ID, product name, or CWE/Technique ID. Examples: "process spawning powershell from outlook", "server auto-restarting at night", "unauthenticated read of /etc/passwd via crafted URL", "encrypted files and ransom note left behind" - "web": exploit code, POC (proof of concept), recent zero-day news, live threat intel Also decide which Qdrant collections to search: "cve" — vulnerability entries (CVEs, descriptions, CVSS) "mitre" — MITRE ATT&CK techniques (T-codes, procedures) "capec" — CAPEC attack patterns (CAPEC-IDs, attack descriptions) "cwe" — CWE weaknesses (CWE-IDs, weakness taxonomy) Use the smallest set of collections needed. Most queries only need "cve". "investigate" queries should include "cve" + "mitre" + "cwe". Return JSON with EXACTLY this format: {"intent": "search", "collections": ["cve"], "reasoning": "short reason here"}""" REWRITE_PROMPT = """You are a CVE search query optimizer. Reformulate the user's original query to maximize retrieval quality in a vector database. Original query: {question} Rules: - If the query mentions a CVE ID (e.g. "CVE-2021-44228"), expand it: "CVE-2021-44228 Log4Shell Log4j JNDI remote code execution vulnerability" - If vendor/product names appear, keep them verbatim - If asking about CVSS/severity, include those terms - If asking about a technique (T1059), prefix with "MITRE ATT&CK" - If a weakness type (buffer overflow, XSS), prefix with "CWE" - Keep the reformulated query under 300 characters Return ONLY the reformulated query text, nothing else.""" REWRITE_IRRELEVANT_PROMPT = """The previous search returned documents that were NOT RELEVANT to the user's question. Broaden or rephrase the query to improve retrieval. Original query: {question} Strategy: - If the query is too specific (e.g. "Windows 10 build 19041 CVE-2024-XXXXX"), broaden it (e.g. "Windows 10 privilege escalation vulnerability") - If using technical jargon, try common synonyms - If searching by symptom, try searching by the vulnerability class (e.g. "remote code execution in web servers") - If all else fails, extract the core security concept (e.g. "authentication bypass", "SQL injection") - Keep under 300 characters Return ONLY the reformulated query text, nothing else.""" REWRITE_HALLUCINATION_PROMPT = """The previous answer contained information NOT SUPPORTED by the retrieved documents. Rephrase the query to get better grounding context. Original query: {question} Strategy: - Focus on verifiable facts: ask for specific CVE IDs, CVSS scores, or affected versions - If the query was open-ended (e.g. "tell me about Log4j"), narrow to specific questions - Add "with specific CVE references and CVSS scores" to constrain - Keep under 300 characters Return ONLY the reformulated query text, nothing else.""" REWRITE_INCOMPLETE_PROMPT = """The previous answer was INCOMPLETE — it did not fully address the user's question. Rephrase to ensure comprehensive coverage. Original query: {question} Strategy: - If the query has multiple parts, separate them with "AND" - If asking about impact, attack vectors, or mitigations, include those terms explicitly - Add "including details on" followed by the missing aspects - Keep under 300 characters Return ONLY the reformulated query text, nothing else.""" GRADE_PROMPT = """You are a document relevance grader for CVE vulnerability search results. User question: {question} Retrieved document: {context} Determine if this document is relevant to answering the user question. Consider: CVE ID match, vulnerability type match, product/version match, CVSS severity match. Return JSON with EXACTLY this format: {"binary_score": "yes", "confidence": 0.85, "reason": "short reason here"} binary_score must be "yes" or "no".""" GRADE_BATCH_PROMPT = """You are a document relevance grader for CVE vulnerability search results. User question: {question} Documents to grade: {numbered_docs} For EACH document, decide if it contains information that is useful for answering the question. Grade "yes" if the document: - Mentions the specific CVE, product, vendor, or weakness asked about, OR - Contains information about the same vulnerability class, attack type, or severity, OR - Provides useful context (similar CVEs, related weaknesses, affected products) Grade "no" only if the document is completely unrelated to the question topic. Return JSON with EXACTLY this format (one entry per document, index matches the [N] prefix): {{"grades": [{{"index": 1, "binary_score": "yes"}}, {{"index": 2, "binary_score": "no"}}]}} binary_score must be "yes" or "no". Include ALL documents in the grades array.""" GENERATE_PROMPT = """You are a CVE vulnerability analyst assistant. Answer the user's question using ONLY the provided context. {memory_context} Retrieved vulnerabilities: {retrieved_context} {kg_context} Guidelines: - Cite specific CVE IDs when referencing vulnerabilities - Include CVSS scores if available in context - Mention affected products/vendors from context - If context is insufficient, say: "I don't have enough information to fully answer this." - Be concise but thorough - Do NOT invent CVEs, scores, or products not present in context User question: {question} Answer:""" GENERATE_NO_CONTEXT = """You are a CVE vulnerability analyst assistant. {memory_context} No relevant vulnerability data was found in the database for this query. User question: {question} If you have relevant past context from memory, use it. Otherwise, respond with: "I couldn't find specific vulnerability data for your query in our database. Please try rephrasing or searching for a specific CVE ID or product name." Do NOT fabricate vulnerability information.""" REFLECT_HALLUCINATION_PROMPT = """You are a factual accuracy checker for CVE vulnerability responses. Retrieved context (ground truth): {context} Generated answer: {generation} Check whether EVERY claim in the generated answer is supported by the retrieved context. Pay special attention to: CVE IDs, CVSS scores, product names, version numbers, vulnerability descriptions. Return JSON with EXACTLY this format: {{"is_grounded": "yes", "unsupported_claims": [], "score": 1.0}} is_grounded must be "yes" or "no". If "no", list each unsupported claim. score: 1.0 = fully grounded, 0.0 = completely fabricated.""" REFLECT_COMPLETENESS_PROMPT = """You are a completeness checker for CVE vulnerability responses. Original user question: {question} Generated answer: {generation} Assess whether the answer fully addresses the user's question. Consider: Did it answer the specific question? Is anything important missing? Return JSON with EXACTLY this format: {{"is_complete": "yes", "missing_aspects": [], "score": 1.0}} is_complete must be "yes" or "no". If "no", list missing aspects. score: 1.0 = fully addresses, 0.0 = irrelevant.""" STRUCTURED_REWRITE_PROMPT = """You are a CVE search planner. Convert the user's query into a JSON retrieval plan. User query: {question} Memory / past context (may be empty): {memory_context} Knowledge-graph taxonomy hints (auto-extracted, may be empty): {cheat_sheet_hints} Produce JSON with EXACTLY these fields: {{ "hyde_doc": "<2-3 sentence hypothetical vulnerability report that would perfectly answer this query, OR empty string if the query already contains CVE IDs or specific technical terms>", "search_query": "", "kg_seeds": [{{"node_label": "CVE|CWE|CAPEC|Technique|Tactic|Product|Vendor", "node_id": "..."}}], "filters": {{"severity": "CRITICAL|HIGH|MEDIUM|LOW|null", "year": "YYYY|null", "is_in_kev": true|false|null}} }} Rules: - Populate kg_seeds when the query references a CVE-ID, CWE-ID, CAPEC-ID, Technique (Txxxx), Tactic (TAxxxx), product name, or vendor name. - Leave hyde_doc empty string if the query already has specific technical terms — only generate it for vague/symptom queries. - Use filters only when the user explicitly mentions severity, year, or KEV status. - Return ONLY the JSON, no prose.""" HYDE_PROMPT = """You are writing a hypothetical CVE vulnerability report to bootstrap retrieval (HyDE technique). User's observed behavior or symptom: {question} Knowledge-graph taxonomy hints (may be empty): {cheat_sheet_hints} Write a 3-4 sentence vulnerability report that, if it existed in the database, would perfectly answer the user's query. Include: a plausible CVE-ID format (CVE-YYYY-NNNNN), CVSS severity terms, affected product/vendor names, weakness classification, and attack vector description. Do NOT fabricate specific real CVE IDs unless the user already provided one. Return ONLY the report text, no JSON, no prose.""" TRANSLATE_SYMPTOM_PROMPT = """You are a CTI analyst translating a free-text security symptom or log observation into structured security entities. Observed symptom / log line: {symptom} Knowledge-graph taxonomy hints (may be empty): {hints} Return JSON only — no prose, no markdown fences: {{ "techniques": ["Txxxx", ...], "cwes": ["CWE-N", ...], "keywords": ["keyword1", "keyword2", ...] }} Rules: - techniques: MITRE ATT&CK technique IDs most likely associated with this symptom (max 5). - cwes: CWE IDs for the underlying weakness (max 5). - keywords: 3-6 dense-retrieval search terms that would find relevant CVEs (specific nouns/verbs, not generic words). - Use the taxonomy hints if provided to improve accuracy."""