From dca0eef0ec433f6bcad17e65bbf7c62f28660573 Mon Sep 17 00:00:00 2001 From: Maxence Haouari Date: Tue, 19 May 2026 15:39:49 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(backend)=20improve=20url=20halluci?= =?UTF-8?q?nation=20instruction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add details to improve agent performance. --- CHANGELOG.md | 1 + src/backend/chat/agents/conversation.py | 16 +++++++++++----- .../agents/test_build_conversation_agent.py | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e95152b2..a9d083c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ and this project adheres to - ✨(dev) setup Tilt for local development - 🐛(front) project modal now respects document-upload feature flag - 🐛(back) self-doc tool no longer triggers on generic or document questions +- 🐛(backend) improve url hallucination instruction ## [0.0.15] - 2026-03-31 diff --git a/src/backend/chat/agents/conversation.py b/src/backend/chat/agents/conversation.py index 817b57ef..7bf61e47 100644 --- a/src/backend/chat/agents/conversation.py +++ b/src/backend/chat/agents/conversation.py @@ -17,11 +17,17 @@ logger = logging.getLogger(__name__) PREVENT_URL_HALLUCINATION_INSTRUCTION = ( - "Never invent or guess URLs. " - "Only include URLs explicitly found in tool outputs (e.g., web search results) " - "or in provided documents when available. Do not introduce new URLs." - "If you need to reference a web page that was not returned by a tool, " - "use a descriptive placeholder such as [official link] instead of a URL." + "URL POLICY (STRICT): Only include a URL if it appears verbatim in a tool result " + "or the user's current message. " + "Never write a URL in any other context — not in direct answers, " + "suggestions, examples, templates, " + "code blocks, or resource recommendations. " + "Never write a URL to well-known websites you know from training. " + "When no verified URL is available, refer to resources " + "by plain text name only (e.g., 'the ANSSI website'). " + "When you cannot access a linked document, do not generate " + "fictional templates or mock examples of " + "its content — ask the user to share the relevant content directly." ) MOCKED_RESPONSE = """ diff --git a/src/backend/chat/tests/agents/test_build_conversation_agent.py b/src/backend/chat/tests/agents/test_build_conversation_agent.py index 6ceb15a4..0b82b58f 100644 --- a/src/backend/chat/tests/agents/test_build_conversation_agent.py +++ b/src/backend/chat/tests/agents/test_build_conversation_agent.py @@ -23,7 +23,7 @@ def assert_base_instructions(instructions, date_str=None, language_str=""): assert instructions[2].__name__ == "enforce_response_language" assert instructions[2]() == language_str assert instructions[3].__name__ == "prevent_url_hallucination" - assert "Never invent or guess URLs" in instructions[3]() + assert "URL POLICY" in instructions[3]() @pytest.fixture(autouse=True)