VibecoderMcSwaggins commited on
Commit
f882609
·
1 Parent(s): 13be9d7

fix: make ResearchReport.references optional with default

Browse files

The LLM doesn't always return the references field, causing validation
failures. Adding default_factory=list makes it optional.

TDD: Added tests/unit/utils/test_models.py with coverage for this case.

Fixes #23

src/utils/models.py CHANGED
@@ -213,7 +213,8 @@ class ResearchReport(BaseModel):
213
  conclusion: str = Field(description="Overall conclusion")
214
 
215
  references: list[dict[str, str]] = Field(
216
- description="Formatted references with title, authors, source, URL"
 
217
  )
218
 
219
  # Metadata
 
213
  conclusion: str = Field(description="Overall conclusion")
214
 
215
  references: list[dict[str, str]] = Field(
216
+ default_factory=list,
217
+ description="Formatted references with title, authors, source, URL",
218
  )
219
 
220
  # Metadata
tests/unit/utils/test_models.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Unit tests for data models."""
2
+
3
+ from src.utils.models import ReportSection, ResearchReport
4
+
5
+
6
+ class TestResearchReport:
7
+ """Tests for ResearchReport model."""
8
+
9
+ def test_references_has_default(self) -> None:
10
+ """ResearchReport should allow creation without references field.
11
+
12
+ This is critical because LLMs don't always return the references
13
+ field, and we shouldn't fail validation when it's missing.
14
+ """
15
+ report = ResearchReport(
16
+ title="Test Report",
17
+ executive_summary="A" * 100, # min_length=100
18
+ research_question="Does drug X help condition Y?",
19
+ methodology=ReportSection(title="Methods", content="We searched..."),
20
+ hypotheses_tested=[{"hypothesis": "test", "supported": True}],
21
+ mechanistic_findings=ReportSection(title="Mechanisms", content="Found..."),
22
+ clinical_findings=ReportSection(title="Clinical", content="Trials show..."),
23
+ drug_candidates=["Drug A"],
24
+ limitations=["Small sample"],
25
+ conclusion="Promising results.",
26
+ sources_searched=["pubmed"],
27
+ total_papers_reviewed=10,
28
+ search_iterations=2,
29
+ confidence_score=0.8,
30
+ # NOTE: references intentionally omitted
31
+ )
32
+
33
+ # Should have empty list as default
34
+ assert report.references == []
35
+
36
+ def test_references_can_be_provided(self) -> None:
37
+ """ResearchReport should accept references when provided."""
38
+ refs = [{"title": "Paper 1", "url": "https://example.com"}]
39
+ report = ResearchReport(
40
+ title="Test Report",
41
+ executive_summary="A" * 100,
42
+ research_question="Does drug X help condition Y?",
43
+ methodology=ReportSection(title="Methods", content="We searched..."),
44
+ hypotheses_tested=[],
45
+ mechanistic_findings=ReportSection(title="Mechanisms", content="Found..."),
46
+ clinical_findings=ReportSection(title="Clinical", content="Trials show..."),
47
+ drug_candidates=[],
48
+ limitations=[],
49
+ conclusion="Results.",
50
+ confidence_score=0.5,
51
+ references=refs,
52
+ )
53
+
54
+ assert report.references == refs