Spaces:
Sleeping
fix(#61): named-policy bypass not gated on intent (single_brain hardcodes it)
Browse filesPROVEN 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>
- backend/brain_tools.py +19 -10
|
@@ -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.
|
| 949 |
-
#
|
| 950 |
-
#
|
| 951 |
-
#
|
| 952 |
-
#
|
| 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).
|
| 958 |
-
#
|
| 959 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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]
|