fix(osint): refine verifier claim filtering#19509
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the robustness of OSINT (Open Source Intelligence) processes by refining the claim verification mechanism. The changes aim to reduce false positives in unsupported claim detection and align verification heuristics with an evidence-first standard. This is achieved through new code modules that introduce deterministic evidence IDs, enforce provenance requirements, and provide a more intelligent verifier that can distinguish between actual unsupported claims and explicit 'gap' statements. The update also includes comprehensive documentation to guide the implementation and operation of these new hallucination mitigation standards. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (15)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive suite of tools for OSINT hallucination mitigation, including deterministic evidence ID generation, fact/provenance schemas, and a verifier to flag unsupported claims. The changes are well-structured, with new modules, documentation, and tests. My review focuses on refining the implementation of the verifier to improve its accuracy and robustness. I've identified a critical issue in the claim verification logic that could allow hallucinated evidence IDs to pass, a high-severity issue with an overly broad claim detection heuristic, and a few medium-severity suggestions to improve code clarity and follow Python idioms.
| has_evidence_id = bool(EVIDENCE_ID_PATTERN.search(claim)) | ||
| if not has_evidence_id and not any(evidence_id in claim for evidence_id in evidence_ids): |
There was a problem hiding this comment.
There is a critical flaw in the claim verification logic. The current implementation only checks if a claim contains a string that looks like an evidence ID, but it does not validate this ID against the list of known evidence IDs from the provided facts. This means a claim with a hallucinated (i.e., fake but well-formed) evidence ID will incorrectly pass verification. The logic must be changed to ensure that a claim is only considered supported if it contains at least one of the known evidence IDs.
if not any(evidence_id in claim for evidence_id in evidence_ids):| def _is_claim_candidate(sentence: str) -> bool: | ||
| if CLAIM_PATTERN.search(sentence): | ||
| return True | ||
| if re.search(r"\b\d{1,4}\b", sentence): | ||
| return True | ||
| if re.search(r"\b[A-Z][a-z]+\b", sentence): | ||
| return True | ||
| return False |
There was a problem hiding this comment.
The heuristic re.search(r"\b[A-Z][a-z]+\b", sentence) is too broad for identifying claim candidates. It will match the first word of most sentences in English, as well as any proper noun, leading to a high number of false positives. This would cause many ordinary sentences to be flagged as unsupported claims, which runs counter to the goal of reducing noise. The heuristic should be more specific or removed.
def _is_claim_candidate(sentence: str) -> bool:
if CLAIM_PATTERN.search(sentence):
return True
if re.search(r"\b\d{1,4}\b", sentence):
return True
return False| def _drop_tracking_params(params: Iterable[tuple[str, str]]) -> list[tuple[str, str]]: | ||
| cleaned: list[tuple[str, str]] = [] | ||
| for key, value in params: | ||
| if key.startswith("utm_"): | ||
| continue | ||
| if key in TRACKING_QUERY_KEYS: | ||
| continue | ||
| cleaned.append((key, value)) | ||
| return cleaned |
There was a problem hiding this comment.
For improved readability and conciseness, this function can be refactored to use a list comprehension. This is a more idiomatic Python approach for filtering and transforming lists.
def _drop_tracking_params(params: Iterable[tuple[str, str]]) -> list[tuple[str, str]]:
return [
(key, value)
for key, value in params
if not key.startswith("utm_") and key not in TRACKING_QUERY_KEYS
]| def _collect_evidence_ids(facts: Iterable[Fact]) -> List[str]: | ||
| evidence_ids: List[str] = [] | ||
| for fact in facts: | ||
| for prov in fact.provenance: | ||
| if prov.evidence_id: | ||
| evidence_ids.append(prov.evidence_id) | ||
| return evidence_ids |
There was a problem hiding this comment.
This function can be made more concise and Pythonic by using a nested list comprehension to collect the evidence IDs. This improves readability by expressing the logic in a single statement.
def _collect_evidence_ids(facts: Iterable[Fact]) -> List[str]:
return [
prov.evidence_id for fact in facts for prov in fact.provenance if prov.evidence_id
]|
Temporarily closing to reduce Actions queue saturation and unblock #22241. Reopen after the golden-main convergence PR merges. |
1 similar comment
|
Temporarily closing to reduce Actions queue saturation and unblock #22241. Reopen after the golden-main convergence PR merges. |
Motivation
Description
GAP_PREFIXESand_is_gap_statementto ignore sentences starting with explicit gap phrases.EVIDENCE_ID_PATTERNdetection and updateextract_claimsandverify_reportto prefer evidence-bearing statements when deciding unsupported claims._is_claim_candidateto balance sensitivity and reduce noise.tests/test_verifier_flags_unsupported.pyto include an explicit unknown/gap sentence and assert the verifier still flags unsupported claims appropriately.Testing
pytest tests/test_verifier_flags_unsupported.py tests/test_provenance_required.py tests/test_unknown_degradation.py tests/test_two_source_promotion.py tests/test_deterministic_evidence_ids.py, and all tests passed (5 passed).{ "agent_id": "codex", "task_id": "osint-hallucination-mitigation-mws", "prompt_hash": "9d6a71f809270db4fc2c78ef7741f3517a60cac3e92488d811a3e6b0cac9a49b", "domains": ["osint", "governance", "documentation", "testing"], "verification_tiers": ["C"], "debt_delta": 0, "declared_scope": { "paths": [ "packages/osint/src/hallucination/", "tests/test_provenance_required.py", "tests/test_unknown_degradation.py", "tests/test_verifier_flags_unsupported.py", "tests/test_two_source_promotion.py", "tests/test_deterministic_evidence_ids.py", "docs/standards/osint-hallucination-mitigation.md", "docs/security/data-handling/osint-hallucination-mitigation.md", "docs/ops/runbooks/osint-hallucination-mitigation.md", "docs/roadmap/STATUS.json", "prompts/osint/osint-hallucination-mitigation@v1.md", "prompts/registry.yaml" ] }, "allowed_operations": ["create", "edit"] }Codex Task