~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(report): end the bibliography strip at the citation list (#6155)
Ehsane8a945f1c24c
diff --git a/changelog.d/6026.bugfix.md b/changelog.d/6026.bugfix.mdnew file mode 100644index 0000000000..5a830d0945--- /dev/null+++ b/changelog.d/6026.bugfix.md@@ -0,0 +1 @@+A table or a paragraph that the LLM writes after its bibliography is no longer deleted along with it. `_strip_embedded_bibliographies` removed everything from the bibliography heading to the next heading, or to the end of the report when no heading followed, so trailing content was lost from the rendered report. The strip now ends at the citation list. Bulleted and numbered lists placed after a bibliography are still removed, because the citation pattern matches any `- ` or `1. ` line and cannot tell those apart from citation entries.diff --git a/src/local_deep_research/report_generator.py b/src/local_deep_research/report_generator.pyindex cfc0f80860..9c182c1d8a 100644--- a/src/local_deep_research/report_generator.py+++ b/src/local_deep_research/report_generator.py@@ -829,10 +829,36 @@ class IntegratedReportGenerator:else:cursor = block_endelse:- if next_heading_start is not None:- cursor = next_heading_start- else:- cursor = len(content)+ # End the removal at the citation list rather than at the end+ # of the block, so a table, list or paragraph the model wrote+ # after its bibliography survives the strip.+ offset = 0+ citation_end = 0+ non_empty_seen = 0+ trailing_content = False+ for ln in block_text.splitlines(keepends=True):+ substantive = bool(ln.strip())+ non_empty_seen += substantive+ # The note window is the classifier's first-three-non-empty-+ # lines rule, so a block accepted as a bibliography always+ # has a qualifying line here and cannot fall through.+ is_bib_line = bool(+ _CITATION_LINE_RE.match(ln)+ or (_BIB_NOTE_RE.match(ln) and non_empty_seen <= 3)+ or _HR_LINE_RE.match(ln)+ )+ if citation_end and substantive and not is_bib_line:+ trailing_content = True+ break+ offset += len(ln)+ if substantive and is_bib_line:+ citation_end = offset+ if not trailing_content:+ # Nothing substantive follows, so the whole block is the+ # bibliography and is removed as before.+ citation_end = len(block_text)++ cursor = after_heading + citation_endif bib_removed:pieces.append(content[cursor:])diff --git a/tests/report/test_report_generator_helpers.py b/tests/report/test_report_generator_helpers.pyindex f6b6758dc7..1357b11d5c 100644--- a/tests/report/test_report_generator_helpers.py+++ b/tests/report/test_report_generator_helpers.py@@ -681,3 +681,127 @@ class TestStripSubsectionBoilerplate:not in result)assert "Prose body of the analysis." in result+++# ── _strip_embedded_bibliographies ──+++class TestStripEmbeddedBibliographies:+ """Tests for _strip_embedded_bibliographies."""++ BIB = (+ "## Sources\n"+ "[1] https://example.org/one\n"+ "[2] https://example.org/two\n"+ "[3] https://example.org/three\n"+ )++ def _strip(self, generator, content):+ return generator._strip_embedded_bibliographies(content)++ def test_removes_bibliography_at_end_of_content(self, generator):+ result = self._strip(generator, "Analysis prose.\n\n" + self.BIB)+ assert "## Sources" not in result+ assert "https://example.org/one" not in result+ assert result.strip() == "Analysis prose."++ def test_keeps_next_section_when_heading_follows(self, generator):+ content = "Analysis prose.\n\n" + self.BIB + "\n## Conclusion\nDone.\n"+ result = self._strip(generator, content)+ assert "## Sources" not in result+ assert "## Conclusion\nDone." in result++ def test_preserves_trailing_table(self, generator):+ table = "| Date | Event |\n|------|-------|\n| 200 CE | Compiled |\n"+ result = self._strip(+ generator, "Analysis prose.\n\n" + self.BIB + "\n" + table+ )+ assert "## Sources" not in result+ assert table in result++ def test_preserves_trailing_paragraph(self, generator):+ para = "The text survives in multiple recensions.\n"+ result = self._strip(+ generator, "Analysis prose.\n\n" + self.BIB + "\n" + para+ )+ assert "## Sources" not in result+ assert para in result++ def test_preserves_content_between_bibliography_and_next_heading(+ self, generator+ ):+ para = "The text survives in multiple recensions.\n"+ content = (+ "Analysis prose.\n\n"+ + self.BIB+ + "\n"+ + para+ + "\n## Conclusion\nDone.\n"+ )+ result = self._strip(generator, content)+ assert "## Sources" not in result+ assert para in result+ assert "## Conclusion\nDone." in result++ def test_removes_decorative_rule_trailing_the_citations(self, generator):+ para = "The text survives in multiple recensions.\n"+ result = self._strip(+ generator, "Analysis prose.\n\n" + self.BIB + "\n---\n\n" + para+ )+ assert "## Sources" not in result+ assert "\n---\n" not in result+ assert para in result++ def test_removes_bibliography_with_blank_separated_citations(+ self, generator+ ):+ content = (+ "Analysis prose.\n\n"+ "## Sources\n"+ "[1] https://example.org/one\n\n"+ "[2] https://example.org/two\n"+ )+ result = self._strip(generator, content)+ assert "https://example.org/two" not in result+ assert result.strip() == "Analysis prose."++ def test_removes_bibliography_introduced_by_a_lead_in_line(self, generator):+ content = (+ "Analysis prose.\n\n"+ "## References\n"+ "The following sources were consulted:\n"+ "[1] https://example.org/one\n"+ "[2] https://example.org/two\n"+ )+ result = self._strip(generator, content)+ assert "The following sources were consulted" not in result+ assert "https://example.org/two" not in result++ def test_leaves_substantive_heading_with_prose_body(self, generator):+ content = (+ "Analysis prose.\n\n"+ "## Sources of Bias\n"+ "The survey design introduced selection bias throughout.\n"+ )+ result = self._strip(generator, content)+ assert "## Sources of Bias" in result+ assert "selection bias" in result++ def test_preserves_trailing_prose_when_the_note_line_is_far_down(+ self, generator+ ):+ lead_in = (+ "The passage below records the provenance of every claim. " * 7+ )+ para = "The text survives in multiple recensions.\n"+ content = (+ "Analysis prose.\n\n"+ "## Sources\n" + lead_in.rstrip() + "\n"+ "*(Note: the bibliography above lists every source consulted.)*\n"+ "\n" + para+ )+ assert len(lead_in.rstrip()) >= 300+ result = self._strip(generator, content)+ assert "## Sources" not in result+ assert "every source consulted" not in result+ assert para in result