rohitsar567 Claude Opus 4.7 (1M context) commited on
Commit
2d0235b
Β·
1 Parent(s): 995fecb

fix(#61): named-policy bypass not gated on intent (single_brain hardcodes it)

Browse files

PROVEN root cause: single_brain._execute_tool (single_brain.py:1529)
hardcodes intent='recommendation' for EVERY retrieve_policies tool call.
The prior #61 bypass was gated on intent!='recommendation' β†’ dead code
on the live path β†’ every named-policy Q&A was blocked by the profile
gate β†’ 'I couldn't find that policy' (#26/#28, reproduced live 3x).

Removed the intent condition. Safety is the resolver's conservatism, not
intent. Verified under the EXACT production call signature
(intent='recommendation', cold/no-profile): the exact #28 query β†’
count=5 niva-bupa__health-companion-v2022__brochure (was 0); the V2022
variant β†’ count=5; HDFC Optima Restore PED query β†’ count=6; generic
'recommend me a plan' + incomplete profile β†’ count=0 profile_incomplete
(recommendation gate STILL intact). Full pytest rc=0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. backend/brain_tools.py +19 -10
backend/brain_tools.py CHANGED
@@ -945,18 +945,27 @@ async def retrieve_policies(
945
  # NAMED-POLICY Q&A BYPASS (#61, 2026-05-18) β€” a direct factual question
946
  # about a SPECIFIC catalogue policy ("what is the PED waiting period for
947
  # HDFC ERGO Optima Restore?") must be answerable on a cold /
948
- # incomplete-profile session. single_brain's prompt tells the LLM to
949
- # query such questions with policy_filter_ids=None, but the
950
- # profile-complete gate below blocks ALL policy_filter_ids=None
951
- # retrieval until the 7-slot fact-find is done β€” so the bot replied
952
- # "I couldn't find that policy" for policies that ARE indexed (#26/#28).
953
- # The gate exists to not RECOMMEND before fact-find, not to refuse a
954
- # factual lookup. When this is NOT a recommendation call and the query
955
  # unambiguously names a known policy, resolve it and reuse the existing
956
  # TRUSTED known-policy path (legitimately gate-bypassing + getting the
957
- # #61 canonical-family $in expansion in rag/retrieve.py). Broad
958
- # "recommend me a plan" queries name no policy β†’ no match β†’ still gated.
959
- if not policy_filter_ids and (intent or "").lower() != "recommendation":
 
 
 
 
 
 
 
 
 
 
 
960
  _np = _resolve_named_policy(query)
961
  if _np:
962
  policy_filter_ids = [_np]
 
945
  # NAMED-POLICY Q&A BYPASS (#61, 2026-05-18) β€” a direct factual question
946
  # about a SPECIFIC catalogue policy ("what is the PED waiting period for
947
  # HDFC ERGO Optima Restore?") must be answerable on a cold /
948
+ # incomplete-profile session. The profile-complete gate below blocks
949
+ # ALL policy_filter_ids=None retrieval until the 7-slot fact-find is
950
+ # done β€” so the bot replied "I couldn't find that policy" for policies
951
+ # that ARE indexed (#26/#28). The gate exists to not RECOMMEND before
952
+ # fact-find, not to refuse a factual lookup. When the query
 
 
953
  # unambiguously names a known policy, resolve it and reuse the existing
954
  # TRUSTED known-policy path (legitimately gate-bypassing + getting the
955
+ # #61 canonical-family $in expansion in rag/retrieve.py).
956
+ #
957
+ # NOT gated on `intent`: single_brain._execute_tool HARDCODES
958
+ # intent="recommendation" for EVERY tool call (single_brain.py:1529),
959
+ # so an intent-conditioned bypass is dead code on the live path β€” the
960
+ # proven (2026-05-18) #61 root cause: every named-policy Q&A arrived
961
+ # with intent="recommendation" β†’ the bypass never fired β†’ the gate
962
+ # blocked β†’ "I couldn't find that policy". Safety is the RESOLVER's
963
+ # conservatism, not the intent: a broad "recommend me a plan" / generic
964
+ # profile request names NO specific policy β†’ _resolve_named_policy
965
+ # returns None β†’ still fully gated (verified). Only an explicit,
966
+ # unambiguous name (>=2 significant tokens, >=60% coverage,
967
+ # version-aware, top strictly ahead of runner-up) triggers it.
968
+ if not policy_filter_ids:
969
  _np = _resolve_named_policy(query)
970
  if _np:
971
  policy_filter_ids = [_np]