fix(diagnosis): validate contexts before chunking analysis#215
Conversation
|
/oc review pr |
PR Review:
|
| File | Δ | What |
|---|---|---|
analyzer.py |
+43/-12 | New _extract_validated_contexts() helper; metadata validation; context filtering in _extract_scores |
test_integration.py |
+49/-1 | Regression test for context validation; Path import moved under TYPE_CHECKING |
Review
Correctness: The logic is sound. _extract_validated_contexts filters to isinstance(context, str) and _extract_scores now does the same for counting/length metrics. Metadata is validated to dict or None before passing downstream. The regression test directly verifies non-string entries are stripped.
Minor issues:
-
Duplicated filtering logic —
_extract_scores(lines 198-207) and_extract_validated_contexts(lines 220-235) perform identical context extraction + string filtering. Consider having_extract_scoresdelegate to_extract_validated_contextsto DRY it up. -
Indentation inconsistency —
analyzer.py:130-134:
chunking_issues = self._chunking_analyzer.analyze(
question, # 8-space indent (was 4)
contexts,
metadata,
)This uses an 8-space hanging indent while the rest of the file uses 4-space (e.g., the DiagnosisReport call at line 150). Should be consistent with project style.
Tests: The regression test test_chunking_receives_validated_contexts is well-written — uses a capture proxy instead of mocking the full analyzer, and covers string/dict/int/None cases.
Verdict
Approved with minor nits. Fix the indentation and optionally DRY up the duplicated context filtering.
|
🎉 Congratulations @Nithin00614! Your pull request has been successfully merged into main. 🚀 Thank you for contributing to OpenAgentHQ and helping improve the project. We truly appreciate your contribution and hope to see you back with more amazing PRs! Happy Open Sourcing! ❤️ 🌟 This is your first merged contribution to this repository. |

Summary
Fixes #62.
This PR ensures that
ChunkingQualityAnalyzerreceives validated string contexts instead of raw evaluation output.Changes
ChunkingQualityAnalyzerValidation