~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(citation): handle string responses from LLM in follow-up analysis (#3884)
Qeuphc6a14dcfb3ab
diff --git a/changelog.d/+fix-citation-handler-crash.bugfix.md b/changelog.d/+fix-citation-handler-crash.bugfix.mdnew file mode 100644index 0000000000..0e5962a956--- /dev/null+++ b/changelog.d/+fix-citation-handler-crash.bugfix.md@@ -0,0 +1 @@+Fix `AttributeError` in citation handlers during follow-up research when LLMs return string responses instead of message objects.diff --git a/src/local_deep_research/citation_handlers/forced_answer_citation_handler.py b/src/local_deep_research/citation_handlers/forced_answer_citation_handler.pyindex 89b4212b7d..f461b4b94f 100644--- a/src/local_deep_research/citation_handlers/forced_answer_citation_handler.py+++ b/src/local_deep_research/citation_handlers/forced_answer_citation_handler.py@@ -86,7 +86,9 @@ New Sources:{formatted_sources}Return the most likely answer based on evidence consistency."""- fact_check_response = self.llm.invoke(fact_check_prompt).content+ fact_check_response = self.llm.invoke(fact_check_prompt)+ if not isinstance(fact_check_response, str):+ fact_check_response = fact_check_response.contentcurrent_timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M"@@ -120,7 +122,10 @@ CRITICAL INSTRUCTIONS:Remember: A wrong answer is better than no answer for this task."""response = self.llm.invoke(prompt)- content = response.content+ if not isinstance(response, str):+ content = response.content+ else:+ content = response# Final check - if still no direct answer, force extractionif self._needs_answer_extraction(content, question):@@ -185,7 +190,10 @@ RULES:Answer:"""try:- answer = self.llm.invoke(extraction_prompt).content.strip()+ answer = self.llm.invoke(extraction_prompt)+ if not isinstance(answer, str):+ answer = answer.content+ answer = answer.strip()# Format as a proper responsereturn f"{answer}. Based on the available sources, this appears to be the most likely answer. {content}"diff --git a/src/local_deep_research/citation_handlers/precision_extraction_handler.py b/src/local_deep_research/citation_handlers/precision_extraction_handler.pyindex f119f1737b..c125d6c833 100644--- a/src/local_deep_research/citation_handlers/precision_extraction_handler.py+++ b/src/local_deep_research/citation_handlers/precision_extraction_handler.py@@ -134,7 +134,10 @@ PRECISION REQUIREMENTS:Provide the precise answer with citations. Do not create the bibliography, it will be provided automatically."""response = self.llm.invoke(prompt)- content = response.content+ if not isinstance(response, str):+ content = response.content+ else:+ content = response# Apply precision extractioncontent = self._apply_precision_extraction(@@ -242,10 +245,13 @@ List all name variations found:Which is the FULL name (including middle name if present)?"""try:- extraction = self.llm.invoke(extraction_prompt).content+ extraction = self.llm.invoke(extraction_prompt)+ if not isinstance(extraction, str):+ extraction = extraction.content+ extraction_lower = extraction.lower()# Extract the identified full name- if "full name" in extraction.lower():+ if "full name" in extraction_lower:lines = extraction.split("\n")for line in lines:if "full name" in line.lower() or "longest" in line.lower():@@ -305,7 +311,10 @@ Rules:The single answer is:"""try:- answer = self.llm.invoke(extraction_prompt).content.strip()+ answer = self.llm.invoke(extraction_prompt)+ if not isinstance(answer, str):+ answer = answer.content+ answer = answer.strip()# Clean up the answeranswer = answer.split(",")[@@ -369,7 +378,10 @@ Rules:The exact {dimension_type or "dimension"} is:"""try:- answer = self.llm.invoke(extraction_prompt).content.strip()+ answer = self.llm.invoke(extraction_prompt)+ if not isinstance(answer, str):+ answer = answer.content+ answer = answer.strip()# Clean and validate the answerimport re@@ -483,7 +495,10 @@ Context: {content[:1000]}The answer is:"""try:- answer = self.llm.invoke(extraction_prompt).content.strip()+ answer = self.llm.invoke(extraction_prompt)+ if not isinstance(answer, str):+ answer = answer.content+ answer = answer.strip()return f"{answer}. {content}"except Exception:# Return first score found if LLM extraction fails@@ -507,7 +522,10 @@ Context: {content[:1000]}The answer is:"""try:- answer = self.llm.invoke(extraction_prompt).content.strip()+ answer = self.llm.invoke(extraction_prompt)+ if not isinstance(answer, str):+ answer = answer.content+ answer = answer.strip()# Clean to just the year/dateyear_match = self.answer_patterns["year"].search(answer)if year_match:@@ -536,7 +554,10 @@ Context: {content[:1000]}The answer is:"""try:- answer = self.llm.invoke(extraction_prompt).content.strip()+ answer = self.llm.invoke(extraction_prompt)+ if not isinstance(answer, str):+ answer = answer.content+ answer = answer.strip()return f"{answer}. {content}"except Exception:# Fallback to first found number if LLM extraction fails@@ -574,7 +595,11 @@ The answer is:"""List the most important facts (names, numbers, dates) found:"""try:- facts = str(self.llm.invoke(extraction_prompt).content)+ response = self.llm.invoke(extraction_prompt)+ if not isinstance(response, str):+ facts = response.content+ else:+ facts = responsereturn facts[:500]except Exception:# Fallback to truncated previous knowledge if LLM extraction failsdiff --git a/src/local_deep_research/citation_handlers/standard_citation_handler.py b/src/local_deep_research/citation_handlers/standard_citation_handler.pyindex 688449e414..c0a6632bd2 100644--- a/src/local_deep_research/citation_handlers/standard_citation_handler.py+++ b/src/local_deep_research/citation_handlers/standard_citation_handler.py@@ -66,7 +66,9 @@ New Sources:Return any inconsistencies or conflicts found."""if self.is_fact_checking_enabled():- fact_check_response = self.llm.invoke(fact_check_prompt).content+ fact_check_response = self.llm.invoke(fact_check_prompt)+ if not isinstance(fact_check_response, str):+ fact_check_response = fact_check_response.contentelse:fact_check_response = ""@@ -93,5 +95,7 @@ Reflect information from sources critically based on: {fact_check_response}. NevProvide a detailed answer with citations. Do not create the bibliography, it will be provided automatically. Example format: "According to [1], ..." """response = self.llm.invoke(prompt)+ if not isinstance(response, str):+ response = response.content- return {"content": response.content, "documents": documents}+ return {"content": response, "documents": documents}