: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(prompts): cap the label-referencing parent listing (#105660)
Juraj Majerika191c89aba32
diff --git a/posthog/api/test/test_llm_prompt.py b/posthog/api/test/test_llm_prompt.pyindex 993c4476dddd..d3957b6b9145 100644--- a/posthog/api/test/test_llm_prompt.py+++ b/posthog/api/test/test_llm_prompt.py@@ -32,7 +32,11 @@ from posthog.rate_limit import BurstRateThrottle, LLMPromptPublishBurstRateThrotfrom posthog.storage.llm_prompt_cache import get_prompt_by_name_from_cachefrom products.ai_observability.backend.models.llm_prompt import LLMPrompt, LLMPromptDependency, LLMPromptLabel-from products.ai_observability.backend.prompt_references import MAX_PROMPT_REFERENCES+from products.ai_observability.backend.prompt_references import (+ MAX_ACTIVE_REFERENCE_RESULTS,+ MAX_PROMPT_REFERENCES,+ get_active_parents_referencing_label,+)class TestLLMPromptAPI(APIBaseTest):@@ -2415,3 +2419,26 @@ class TestLLMPromptDependenciesAPI(APIBaseTest):format="json",)assert tag_free.status_code == status.HTTP_201_CREATED++ def test_label_parent_listing_is_capped(self):+ base = self._make_prompt("base", label="production")+ assert base is not None+ parents = LLMPrompt.objects.bulk_create(+ LLMPrompt(team=self.team, name=f"parent-{i}", prompt="x", version=1, is_latest=True, created_by=self.user)+ for i in range(MAX_ACTIVE_REFERENCE_RESULTS + 1)+ )+ LLMPromptDependency.objects.bulk_create(+ LLMPromptDependency(+ team=self.team,+ prompt=parent,+ parent_name=parent.name,+ child_name="base",+ child_label="production",+ )+ for parent in parents+ )++ names = get_active_parents_referencing_label(self.team.id, "base", "production")++ assert len(names) == MAX_ACTIVE_REFERENCE_RESULTS+ assert names == sorted(names)diff --git a/products/ai_observability/backend/prompt_references.py b/products/ai_observability/backend/prompt_references.pyindex 3d18baa8d9f0..a6a276f4e6c3 100644--- a/products/ai_observability/backend/prompt_references.py+++ b/products/ai_observability/backend/prompt_references.py@@ -101,7 +101,12 @@ def get_active_references_to(team_id: int, child_name: str) -> list[dict[str, Andef get_active_parents_referencing_label(team_id: int, prompt_name: str, label_name: str) -> list[str]:- """Prompts whose latest or labeled version references `prompt_name` through this label."""+ """Prompts whose latest or labeled version references `prompt_name` through this label.++ Capped like its siblings: the names end up in error messages and dialogs,+ and existence checks stay correct because over the cap still means+ "referenced".+ """return sorted(LLMPromptDependency.objects.filter(team_id=team_id, child_name=prompt_name, child_label=label_name, prompt__deleted=False@@ -110,6 +115,7 @@ def get_active_parents_referencing_label(team_id: int, prompt_name: str, label_n.exclude(parent_name=prompt_name).values_list("parent_name", flat=True).distinct()+ .order_by("parent_name")[:MAX_ACTIVE_REFERENCE_RESULTS])