Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(phai): guide agent to search docs when billing data is unavailable (#61403)

Chris Volzer823bba259f4a
diff --git a/ee/hogai/chat_agent/prompts/base.py b/ee/hogai/chat_agent/prompts/base.py
index ba3e13bf5432..1e509bf9dab0 100644
--- a/ee/hogai/chat_agent/prompts/base.py
+++ b/ee/hogai/chat_agent/prompts/base.py
@@ -243,6 +243,7 @@ TOOL_USAGE_POLICY_PROMPT = """
- The only tool you can't invoke with others at the same time is `web_search`. Only invoke it alone.
- Retry failed tool calls only if the error proposes retrying, or suggests how to fix tool arguments
- Before describing PostHog support capabilities, data management operations (such as deleting or modifying events), or directing users to contact support, you must search the documentation first using the `search` tool with kind="docs" to verify what is currently offered.
+- Before answering questions about PostHog billing, pricing, plans, or add-ons, you must search the documentation first using the `search` tool with kind="docs" to verify current pricing details. If the billing tool returned no data, do not guess or infer how plans or pricing work — search the docs and be transparent that you cannot access the user's specific billing information.
</tool_usage_policy>
""".strip()
diff --git a/ee/hogai/tools/read_billing_tool/prompts.py b/ee/hogai/tools/read_billing_tool/prompts.py
index 680c0e646058..e446d7d6b54e 100644
--- a/ee/hogai/tools/read_billing_tool/prompts.py
+++ b/ee/hogai/tools/read_billing_tool/prompts.py
@@ -1,3 +1,10 @@
+BILLING_CONTEXT_UNAVAILABLE_PROMPT = (
+ "No billing information available. "
+ "Do not guess or infer billing details, plan pricing, or how specific plans work. "
+ 'Search the PostHog documentation using the `search` tool with kind="docs" for the relevant billing or pricing topic, '
+ "and be transparent with the user that you cannot see their specific billing details."
+)
+
BILLING_CONTEXT_PROMPT = """
<billing_context>
The user's organization has {{subscription_level}} subscription{{#billing_plan}} ({{billing_plan}}){{/billing_plan}}.
diff --git a/ee/hogai/tools/read_billing_tool/test/test_nodes.py b/ee/hogai/tools/read_billing_tool/test/test_nodes.py
index c1c22c5d7cbb..bd523b6d8675 100644
--- a/ee/hogai/tools/read_billing_tool/test/test_nodes.py
+++ b/ee/hogai/tools/read_billing_tool/test/test_nodes.py
@@ -23,6 +23,7 @@ from posthog.schema import (
)
from ee.hogai.context.context import AssistantContextManager
+from ee.hogai.tools.read_billing_tool.prompts import BILLING_CONTEXT_UNAVAILABLE_PROMPT
from ee.hogai.tools.read_billing_tool.tool import ReadBillingTool
from ee.hogai.utils.types import AssistantState
@@ -43,7 +44,7 @@ class TestBillingNode(ClickhouseTestMixin, NonAtomicBaseTest):
async def test_run_with_no_billing_context(self):
with patch.object(self.tool._context_manager, "get_billing_context", return_value=None):
result = await self.tool.execute()
- self.assertEqual(result, "No billing information available")
+ self.assertEqual(result, BILLING_CONTEXT_UNAVAILABLE_PROMPT)
async def test_run_with_billing_context(self):
billing_context = MaxBillingContext(
diff --git a/ee/hogai/tools/read_billing_tool/tool.py b/ee/hogai/tools/read_billing_tool/tool.py
index b165829cd56f..f52944013935 100644
--- a/ee/hogai/tools/read_billing_tool/tool.py
+++ b/ee/hogai/tools/read_billing_tool/tool.py
@@ -14,7 +14,7 @@ from ee.hogai.tool import MaxSubtool
from ee.hogai.tool_errors import MaxToolFatalError
from ee.hogai.utils.types import AssistantState
-from .prompts import BILLING_CONTEXT_PROMPT
+from .prompts import BILLING_CONTEXT_PROMPT, BILLING_CONTEXT_UNAVAILABLE_PROMPT
# sync with frontend/src/scenes/billing/constants.ts
USAGE_TYPES = [
@@ -55,7 +55,7 @@ class ReadBillingTool(MaxSubtool):
async def execute(self) -> str:
billing_context = self._context_manager.get_billing_context()
if not billing_context:
- return "No billing information available"
+ return BILLING_CONTEXT_UNAVAILABLE_PROMPT
formatted_billing_context = await self._format_billing_context(billing_context)
return formatted_billing_context