Fix web search fallback and citation parsing for KB search - #17
Conversation
- Make the KB-empty fallback message directive ("call web_search now")
instead of giving the LLM an easy out to answer from general knowledge
- Inject an assistant-role nudge into the gateway conversation whenever
the web search fallback activates, reinforcing the tool call
- Fix _extract_citation_chunks to handle the actual Anthropic/litellm
citation shapes (nested web_search_tool_result.content[], and the
provider_specific_fields fallback when citations is null) — previously
every citation was silently dropped due to a shape mismatch
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe response handler now directs the model to use web search after empty KB results and extracts additional citation formats. Elevate profile and T&C flows now handle configuration, authorization, upstream, and response-code errors explicitly, while two API routes are disabled. ChangesWeb-search response handling
Elevate profile handling
Disabled API routes
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant ResponseHandler
participant KnowledgeBase
participant GatewayLLM
participant WebSearch
ResponseHandler->>KnowledgeBase: search_knowledge_base
KnowledgeBase-->>ResponseHandler: return no chunks
ResponseHandler->>GatewayLLM: append web_search instruction
GatewayLLM->>WebSearch: invoke web_search
WebSearch-->>ResponseHandler: return search results and citations
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@chatbot/services/response_handlers/base_response_handler.py`:
- Around line 822-859: Update the citation extraction around
_collect_from_tool_results and the flat citation loop to obtain each excerpt
from the provider’s citation block rather than web_search_tool_result.content
items, which lack cited_text. Preserve the existing title and URL extraction,
and populate each chunk’s text with the corresponding quoted citation excerpt
for both Anthropic and fallback provider payloads.
- Around line 501-510: Update the fallback branch in the response-handling flow
around tool_name == 'search_knowledge_base' so the web-search nudge uses a
provider-supported prefill or continuation mechanism rather than appending a
plain assistant message. Gate this behavior to the Anthropic provider if no
generic backend-supported mechanism exists, while preserving the existing
condition requiring use_web_search and no new_chunks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0f43108c-f9ae-40f7-98b4-1cc849256e7e
📒 Files selected for processing (1)
chatbot/services/response_handlers/base_response_handler.py
- Disable /api/profile/ and /api/get-ip-location/ routes: the former
allowed unvalidated profile creation (arbitrary email/password/
other_params), the latter is unused.
- get-profile and accept-tnc now surface Elevate's actual error and
status code (401 unauthorized, 5xx service error) instead of
silently defaulting or always returning 502, matching the pattern
already used in logout.
- update_elevate_profile returns structured {error, status_code}
like fetch_elevate_user/logout_elevate_user instead of a bare {}.
- Drop local access_token pre-checks in get-profile/accept-tnc; a
missing token now surfaces as Elevate's own 401 rather than a
locally synthesized 400.
|
@coderabbitai review, please review latest push |
|
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@chatbot/utils/elevate/profile_utils.py`:
- Around line 209-212: Update the responseCode validation in the profile update
flow to safely handle an explicit null value before calling lower(), while
preserving the existing unexpected-response logging and response.status_code
return. Ensure missing, null, and non-"ok" response codes follow the
elevate_server_error branch without reaching the broad exception handler.
- Around line 175-178: Add an early missing-access-token guard to both
fetch_elevate_user and update_elevate_profile before constructing Elevate
request headers, reusing each function’s existing unauthorized response so
callers receive 401 instead of triggering InvalidHeader and a 502. The affected
api_views.py sites at lines 226-233 and 301-309 require no direct changes; they
should continue propagating the utility functions’ unauthorized results.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3065eeee-ae4a-4eac-9510-898707d952f2
📒 Files selected for processing (3)
chatbot/urls.pychatbot/utils/elevate/profile_utils.pychatbot/views/api_views.py
9821f00
into
ELEVATE-Project:release-1.1.1
Summary by CodeRabbit
/api/profile/and/api/get-ip-location/endpoints.