Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rag/evaluator/faithfulness_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def check(self, feedback: str, context_chunks: list[dict]) -> float:
logger.info("faithfulness_no_claims_extracted")
return 0.5 # Default to neutral if no extractable claims

# Concatenate context text
context_text = " ".join([chunk.get("text", "") for chunk in context_chunks])
# Concatenate context text; treat missing or None text as empty
context_text = " ".join([chunk.get("text") or "" for chunk in context_chunks])

# Check each claim for support
supported = 0
Expand Down
14 changes: 9 additions & 5 deletions tests/unit/test_faithfulness_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,25 @@ def test_minimum_overlap_required(self, checker):
assert isinstance(supported, bool)
# Need at least 2 meaningful tokens for support

@pytest.mark.xfail(
strict=True,
reason="issue #60: faithfulness checker crashes when a context chunk has text: None",
)
def test_none_context_chunk_text(self, checker):
"""Test handling of None in context chunk text."""
feedback = "Has Python skills"
context_chunks = [{"text": None}]

score = checker.check(feedback, context_chunks)

# Should handle gracefully
# Should handle gracefully instead of raising TypeError
assert isinstance(score, float)
assert 0.0 <= score <= 1.0

# Mixed None and real text must also be join-safe
mixed_score = checker.check(
"Knows Python.",
[{"text": None}, {"text": "Knows Python well"}],
)
assert isinstance(mixed_score, float)
assert 0.0 <= mixed_score <= 1.0

def test_missing_text_key_in_chunk(self, checker):
"""Test handling of missing 'text' key in context chunk."""
feedback = "Has Python skills"
Expand Down
Loading