Skip to content

Commit 5393027

Browse files
northdpoleclaude
andcommitted
feat(comprehension): OWASP_CX_COMPLETE asks for every part of multi-part and cross-standard questions
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 59fdb06 commit 5393027

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎application/tests/comprehension_test.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,3 +844,21 @@ def execute(self, *a, **k):
844844
db = mock.Mock(session=Session())
845845
out = store.changed_chunks(db, "OWASP/X", chunks)
846846
self.assertEqual([c[:2] for c in out], [("a.md", 1), ("b.md", 0)])
847+
848+
849+
class CompleteRuleTest(unittest.TestCase):
850+
def test_complete_flag_adds_rule(self):
851+
from application.utils.comprehension.synthesize import COMPLETE_RULE, synthesize
852+
853+
seen = []
854+
855+
def llm(system, user):
856+
seen.append(system)
857+
return "A [1]"
858+
859+
with mock.patch.dict(os.environ, {"OWASP_CX_COMPLETE": "1"}):
860+
synthesize("q", [("t", ["u"])], llm)
861+
with mock.patch.dict(os.environ, {"OWASP_CX_COMPLETE": ""}):
862+
synthesize("q", [("t", ["u"])], llm)
863+
self.assertIn(COMPLETE_RULE, seen[0])
864+
self.assertNotIn(COMPLETE_RULE, seen[1])

‎application/utils/comprehension/flags.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"LONGCTX", # questions naming 1-3 projects: read the whole project text, not snippets
2323
"FAST", # final-answer model runs with thinking off (latency)
2424
"PROJROUTE", # no project named: pick one by similarity to project overviews
25+
"COMPLETE", # answer every part and every named standard; include all stated items
2526
"EDITION", # answer for the edition/year/version the question names; never mix editions
2627
"DECOMPOSE", # multi-part questions: answer each part separately, then combine
2728
)

‎application/utils/comprehension/synthesize.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
)
3636

3737

38+
COMPLETE_RULE = (
39+
" Cover every part of the question: if it has several parts or names several standards or "
40+
"projects, answer each one in turn (one short line per part), and when asked to list or compare, "
41+
"include every item the sources state. For a 'which is NOT ...' question, check each option "
42+
"against the sources before choosing."
43+
)
44+
45+
3846
def synthesize(
3947
question: str,
4048
hits: Sequence[Tuple[str, List[str]]],
@@ -47,6 +55,8 @@ def synthesize(
4755

4856
if flags.on("EDITION"):
4957
system += EDITION_RULE
58+
if flags.on("COMPLETE"):
59+
system += COMPLETE_RULE
5060
numbered = "\n\n".join(
5161
f"[{i + 1}] {t.split(chr(10) + chr(10) + 'Citations:')[0]}"
5262
for i, (t, _) in enumerate(hits)

0 commit comments

Comments
 (0)