From da451ffff76c9071f2082c2b0d53bfd0f3cf23de Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Fri, 13 Feb 2026 13:22:52 +0200 Subject: [PATCH] Handle page not found as informational status instead of error --- .../new_chat/tools/notion/update_page.py | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/surfsense_backend/app/agents/new_chat/tools/notion/update_page.py b/surfsense_backend/app/agents/new_chat/tools/notion/update_page.py index 2fbc0a5f3..f705bc1d0 100644 --- a/surfsense_backend/app/agents/new_chat/tools/notion/update_page.py +++ b/surfsense_backend/app/agents/new_chat/tools/notion/update_page.py @@ -46,15 +46,20 @@ def create_update_notion_page_tool( Returns: Dictionary with: - - status: "success", "rejected", or "error" + - status: "success", "rejected", "not_found", or "error" - page_id: Updated page ID (if success) - url: URL to the updated page (if success) - title: Current page title (if success) - message: Result message - IMPORTANT: If status is "rejected", the user explicitly declined the action. - Respond with a brief acknowledgment (e.g., "Understood, I didn't update the page.") - and move on. Do NOT ask for alternatives or troubleshoot. + IMPORTANT: + - If status is "rejected", the user explicitly declined the action. + Respond with a brief acknowledgment (e.g., "Understood, I didn't update the page.") + and move on. Do NOT ask for alternatives or troubleshoot. + - If status is "not_found", inform the user conversationally using the exact message provided. + Example: "I couldn't find the page '[page_title]' in your indexed Notion pages. [message details]" + Do NOT treat this as an error. Do NOT invent information. Simply relay the message and + ask the user to verify the page title or check if it's been indexed. Examples: - "Add 'New meeting notes from today' to the 'Meeting Notes' page" @@ -83,11 +88,20 @@ def create_update_notion_page_tool( ) if "error" in context: - logger.error(f"Failed to fetch update context: {context['error']}") - return { - "status": "error", - "message": context["error"], - } + error_msg = context["error"] + # Check if it's a "not found" error (softer handling for LLM) + if "not found" in error_msg.lower(): + logger.warning(f"Page not found: {error_msg}") + return { + "status": "not_found", + "message": error_msg, + } + else: + logger.error(f"Failed to fetch update context: {error_msg}") + return { + "status": "error", + "message": error_msg, + } page_id = context.get("page_id") connector_id_from_context = context.get("account", {}).get("id")