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.

feat(prompts): Fetch prompts by label (#71509)

Juraj Majerikcb7a53a293f2
diff --git a/posthog/api/llm_prompt.py b/posthog/api/llm_prompt.py
index 6e793464ba97..6457ce6dde17 100644
--- a/posthog/api/llm_prompt.py
+++ b/posthog/api/llm_prompt.py
@@ -175,6 +175,16 @@ class LLMPromptViewSet(
return prompt
def _track_prompt_fetch(self, prompt: dict[str, Any]) -> None:
+ # prompt_label + prompt_version together answer "what was the production label
+ # actually serving at time X" from the event stream alone.
+ properties = {
+ "prompt_id": prompt["id"],
+ "prompt_name": prompt["name"],
+ "prompt_version": prompt["version"],
+ "prompt_label": prompt.get("label"),
+ "prompt_is_latest": prompt["is_latest"],
+ "prompt_first_version_created_at": prompt["first_version_created_at"],
+ }
if not settings.TEST:
try:
capture_internal(
@@ -183,28 +193,12 @@ class LLMPromptViewSet(
event_source=PROMPT_FETCHED_EVENT_SOURCE,
distinct_id=str(self.team.uuid),
timestamp=None,
- properties={
- "prompt_id": prompt["id"],
- "prompt_name": prompt["name"],
- "prompt_version": prompt["version"],
- "prompt_is_latest": prompt["is_latest"],
- "prompt_first_version_created_at": prompt["first_version_created_at"],
- },
+ properties=properties,
)
except Exception as err:
capture_exception(err)
- report_team_action(
- self.team,
- "llma prompt fetched",
- {
- "prompt_id": prompt["id"],
- "prompt_name": prompt["name"],
- "prompt_version": prompt["version"],
- "prompt_is_latest": prompt["is_latest"],
- "prompt_first_version_created_at": prompt["first_version_created_at"],
- },
- )
+ report_team_action(self.team, "llma prompt fetched", properties)
def _get_list_params(self, request: Request) -> dict[str, Any]:
serializer = LLMPromptListQuerySerializer(data=request.query_params)
@@ -270,9 +264,15 @@ class LLMPromptViewSet(
def get_by_name(self, request: Request, prompt_name: str = "", **kwargs) -> Response:
query_params = self._get_get_by_name_params(request)
version = cast(int | None, query_params.get("version"))
+ label = cast(str | None, query_params.get("label"))
content_mode = cast(str, query_params.get("content", "full"))
- prompt = get_prompt_by_name_from_cache(self.team, prompt_name, version)
+ prompt = get_prompt_by_name_from_cache(self.team, prompt_name, version, label=label)
if prompt is None:
+ if label is not None:
+ return Response(
+ {"detail": f"Prompt '{prompt_name}' not found or has no label '{label}'."},
+ status=status.HTTP_404_NOT_FOUND,
+ )
return self._prompt_not_found_response(prompt_name)
self._track_prompt_fetch(prompt)
diff --git a/posthog/api/llm_prompt_serializers.py b/posthog/api/llm_prompt_serializers.py
index 5a15d4c8522e..cd0308d2cd7b 100644
--- a/posthog/api/llm_prompt_serializers.py
+++ b/posthog/api/llm_prompt_serializers.py
@@ -99,6 +99,14 @@ class LLMPromptFetchQuerySerializer(serializers.Serializer):
class LLMPromptGetByNameQuerySerializer(LLMPromptFetchQuerySerializer):
+ label = serializers.CharField( # type: ignore[assignment]
+ required=False,
+ max_length=PROMPT_LABEL_NAME_MAX_LENGTH,
+ help_text=(
+ "Fetch the version this label currently points to, e.g. 'production'. "
+ "Lowercase letters, numbers, dots, hyphens and underscores. Mutually exclusive with version."
+ ),
+ )
content = serializers.ChoiceField(
choices=CONTENT_MODE_CHOICES,
required=False,
@@ -106,6 +114,17 @@ class LLMPromptGetByNameQuerySerializer(LLMPromptFetchQuerySerializer):
help_text=CONTENT_MODE_HELP,
)
+ def validate_label(self, value: str) -> str:
+ # Fetching also writes to the cache (miss sentinels under caller-controlled keys),
+ # so impossible label names are rejected before any cache touch — and a caller
+ # sending 'Production' gets the naming rules instead of a confusing 404.
+ return validate_prompt_label_name_value(value)
+
+ def validate(self, attrs: dict[str, Any]) -> dict[str, Any]:
+ if attrs.get("version") is not None and attrs.get("label") is not None:
+ raise serializers.ValidationError("Use either version or label, not both.")
+ return attrs
+
class LLMPromptListQuerySerializer(serializers.Serializer):
search = serializers.CharField(
@@ -415,6 +434,10 @@ class LLMPromptPublicSerializer(serializers.Serializer):
help_text="Flat list of markdown headings parsed from the prompt. Useful as a lightweight table of contents.",
)
version = serializers.IntegerField()
+ label = serializers.CharField( # type: ignore[assignment]
+ required=False,
+ help_text="The label this prompt was fetched by. Only present when fetching with the label parameter.",
+ )
created_at = serializers.DateTimeField()
updated_at = serializers.DateTimeField()
deleted = serializers.BooleanField()
diff --git a/posthog/api/test/test_llm_prompt.py b/posthog/api/test/test_llm_prompt.py
index 308b9f9d92c5..e7334f01c464 100644
--- a/posthog/api/test/test_llm_prompt.py
+++ b/posthog/api/test/test_llm_prompt.py
@@ -1074,6 +1074,80 @@ class TestLLMPromptLabelsAPI(APIBaseTest):
assert response.status_code == status.HTTP_204_NO_CONTENT
assert LLMPromptLabel.objects.filter(team=self.team).count() == 0
+ def _fetch_by_label(self, prompt_name: str, label_name: str):
+ return self.client.get(f"/api/environments/{self.team.id}/llm_prompts/name/{prompt_name}/?label={label_name}")
+
+ def _set_label_committed(self, prompt_name: str, label_name: str, version: int):
+ # Cache invalidation rides on transaction.on_commit, which TestCase never fires
+ # on its own — execute the callbacks so these tests exercise the invalidation
+ # exactly as a committed request would.
+ with self.captureOnCommitCallbacks(execute=True):
+ return self._set_label(prompt_name, label_name, version)
+
+ def test_fetch_by_label_returns_resolved_version_and_survives_label_move(self):
+ self.create_prompt_version(version=1, is_latest=False, prompt="v1 content")
+ self.create_prompt_version(version=2, prompt="v2 content")
+ self._set_label_committed("my-prompt", "production", 1)
+
+ first_fetch = self._fetch_by_label("my-prompt", "production")
+ assert first_fetch.status_code == status.HTTP_200_OK
+ assert first_fetch.json()["version"] == 1
+ assert first_fetch.json()["prompt"] == "v1 content"
+ assert first_fetch.json()["label"] == "production"
+
+ # The move must invalidate the cached label entry the first fetch created —
+ # a stale entry here means the promote button silently doesn't promote.
+ self._set_label_committed("my-prompt", "production", 2)
+
+ second_fetch = self._fetch_by_label("my-prompt", "production")
+ assert second_fetch.status_code == status.HTTP_200_OK
+ assert second_fetch.json()["version"] == 2
+ assert second_fetch.json()["prompt"] == "v2 content"
+
+ def test_fetch_by_label_after_cached_miss_sees_newly_created_label(self):
+ self.create_prompt_version(version=1)
+
+ # This 404 caches a miss sentinel; creating the label must clear it.
+ assert self._fetch_by_label("my-prompt", "production").status_code == status.HTTP_404_NOT_FOUND
+
+ self._set_label_committed("my-prompt", "production", 1)
+
+ response = self._fetch_by_label("my-prompt", "production")
+ assert response.status_code == status.HTTP_200_OK
+ assert response.json()["version"] == 1
+
+ def test_fetch_rejects_invalid_label_params(self):
+ self.create_prompt_version(version=1)
+ self._set_label("my-prompt", "production", 1)
+
+ both_params = self.client.get(
+ f"/api/environments/{self.team.id}/llm_prompts/name/my-prompt/?label=production&version=1"
+ )
+ # Invalid names must be rejected before any cache touch — an unvalidated fetch
+ # writes a miss sentinel under a caller-controlled key and silently 404s.
+ bad_name = self._fetch_by_label("my-prompt", "Production")
+
+ assert both_params.status_code == status.HTTP_400_BAD_REQUEST
+ assert bad_name.status_code == status.HTTP_400_BAD_REQUEST
+
+ def test_fetch_by_label_404s_after_label_delete_and_prompt_archive(self):
+ self.create_prompt_version(version=1)
+ self._set_label_committed("my-prompt", "production", 1)
+ assert self._fetch_by_label("my-prompt", "production").status_code == status.HTTP_200_OK
+
+ with self.captureOnCommitCallbacks(execute=True):
+ self.client.delete(self._label_url("my-prompt", "production"))
+ assert self._fetch_by_label("my-prompt", "production").status_code == status.HTTP_404_NOT_FOUND
+
+ self._set_label_committed("my-prompt", "production", 1)
+ assert self._fetch_by_label("my-prompt", "production").status_code == status.HTTP_200_OK
+
+ # Archive removes labels via a queryset delete — its post_delete signals must
+ # clear the label cache entries too, not just the explicit delete endpoint path.
+ with self.captureOnCommitCallbacks(execute=True):
+ self.client.post(f"/api/environments/{self.team.id}/llm_prompts/name/my-prompt/archive/")
+ assert self._fetch_by_label("my-prompt", "production").status_code == status.HTTP_404_NOT_FOUND
+
def test_label_writes_forbidden_for_read_only_personal_api_key(self):
self.create_prompt_version(version=1)
api_key = self.create_personal_api_key_with_scopes(["llm_prompt:read"])
diff --git a/posthog/settings/data_stores.py b/posthog/settings/data_stores.py
index 48b056625bd4..89633b859fa1 100644
--- a/posthog/settings/data_stores.py
+++ b/posthog/settings/data_stores.py
@@ -589,6 +589,9 @@ FLAGS_CACHE_TTL = int(os.getenv("FLAGS_CACHE_TTL", str(60 * 60 * 24 * 7))) # 7
FLAGS_CACHE_MISS_TTL = int(os.getenv("FLAGS_CACHE_MISS_TTL", str(60 * 60 * 24))) # 1 day
LLM_PROMPTS_CACHE_TTL = int(os.getenv("LLM_PROMPTS_CACHE_TTL", str(60 * 60 * 24))) # 1 day
LLM_PROMPTS_CACHE_MISS_TTL = int(os.getenv("LLM_PROMPTS_CACHE_MISS_TTL", str(60 * 5))) # 5 minutes
+# Label entries resolve a mutable pointer, so they get a short TTL as a hard bound on
+# staleness when a cache fill races an invalidation (signals stay the fast path).
+LLM_PROMPTS_LABEL_CACHE_TTL = int(os.getenv("LLM_PROMPTS_LABEL_CACHE_TTL", str(60))) # 1 minute
CACHES = {
"default": {
diff --git a/posthog/storage/llm_prompt_cache.py b/posthog/storage/llm_prompt_cache.py
index fe31869646e6..c5c114b27287 100644
--- a/posthog/storage/llm_prompt_cache.py
+++ b/posthog/storage/llm_prompt_cache.py
@@ -9,6 +9,7 @@ from posthog.models.team.team import Team
from posthog.storage.hypercache import HyperCache, HyperCacheStoreMissing, KeyType
from posthog.storage.llm_prompt_cache_keys import (
parse_prompt_cache_key,
+ prompt_label_cache_key,
prompt_latest_cache_key,
prompt_version_cache_key,
)
@@ -21,7 +22,11 @@ from posthog.storage.llm_prompt_cache_payloads import (
strip_internal_metadata,
)
-from products.ai_observability.backend.models.llm_prompt import LLMPrompt, annotate_llm_prompt_version_history_metadata
+from products.ai_observability.backend.models.llm_prompt import (
+ LLMPrompt,
+ LLMPromptLabel,
+ annotate_llm_prompt_version_history_metadata,
+)
# Used in tests; keep as module export.
_serialize_prompt = serialize_prompt
@@ -69,12 +74,33 @@ def _get_prompt_version_from_db(team_id: int, prompt_name: str, version: int) ->
return _attach_first_version_id(prompt, team_id, prompt_name)
+def _get_labeled_prompt_from_db(team_id: int, prompt_name: str, label_name: str) -> LLMPrompt | None:
+ label = (
+ LLMPromptLabel.objects.filter(team_id=team_id, prompt_name=prompt_name, name=label_name)
+ .select_related("prompt")
+ .first()
+ )
+ if label is None or label.prompt.deleted:
+ return None
+ return _attach_first_version_id(label.prompt, team_id, prompt_name)
+
+
+def _serialize_labeled_prompt(prompt: LLMPrompt, label_name: str) -> dict[str, Any]:
+ return {**serialize_prompt_version(prompt, include_internal=True), "label": label_name}
+
+
def _load_prompt_cache(cache_key: KeyType) -> dict[str, Any] | HyperCacheStoreMissing:
parsed_key = parse_prompt_cache_key(cache_key)
if parsed_key is None:
return HyperCacheStoreMissing()
- team_id, prompt_name, version = parsed_key
+ team_id, prompt_name, version, label_name = parsed_key
+
+ if label_name is not None:
+ labeled_prompt = _get_labeled_prompt_from_db(team_id, prompt_name, label_name)
+ if labeled_prompt is None:
+ return HyperCacheStoreMissing()
+ return _serialize_labeled_prompt(labeled_prompt, label_name)
if version is None:
prompt = _get_latest_prompt_from_db(team_id, prompt_name)
@@ -97,8 +123,28 @@ llm_prompts_hypercache = HyperCache(
cache_miss_ttl=settings.LLM_PROMPTS_CACHE_MISS_TTL,
)
+# Label entries go through their own instance (same key space) with a short TTL. Latest
+# and version entries hold immutable content, but a label entry is a resolved pointer:
+# a cache fill racing an invalidation can store an already-stale resolution that the
+# generation marker cannot detect. The short TTL bounds that staleness to a minute;
+# signal invalidation still makes the common path near-instant. Label entries are also
+# kept out of S3 (redis-only writes) — an S3 copy has no TTL, so a stale fill there
+# would keep restoring itself past every redis expiry.
+llm_prompts_label_hypercache = HyperCache(
+ namespace="llm_prompts",
+ value="prompt.json",
+ load_fn=_load_prompt_cache,
+ cache_ttl=settings.LLM_PROMPTS_LABEL_CACHE_TTL,
+ cache_miss_ttl=settings.LLM_PROMPTS_LABEL_CACHE_TTL,
+)
+
-def get_prompt_by_name_from_cache(team: Team, prompt_name: str, version: int | None = None) -> dict[str, Any] | None:
+def get_prompt_by_name_from_cache(
+ team: Team,
+ prompt_name: str,
+ version: int | None = None,
+ label: str | None = None,
+) -> dict[str, Any] | None:
latest_key = prompt_latest_cache_key(team.id, prompt_name)
latest_prompt = llm_prompts_hypercache.get_from_cache(latest_key)
@@ -113,6 +159,31 @@ def get_prompt_by_name_from_cache(team: Team, prompt_name: str, version: int | N
except Exception as err:
capture_exception(err)
+ if label is not None:
+ label_key = prompt_label_cache_key(team.id, prompt_name, label)
+ labeled_prompt = llm_prompts_label_hypercache.get_from_cache(label_key)
+ if not isinstance(labeled_prompt, dict):
+ return None
+
+ # The generation marker guards against a stale entry surviving an archive + recreate
+ # of the whole prompt; label moves are covered by the model-signal invalidation.
+ if is_stale_exact_version_entry(labeled_prompt, latest_prompt):
+ try:
+ invalidate_prompt_label_cache(team.id, prompt_name, label)
+ except Exception as err:
+ capture_exception(err)
+
+ db_labeled = _get_labeled_prompt_from_db(team.id, prompt_name, label)
+ if db_labeled is None:
+ return None
+ labeled_prompt = _serialize_labeled_prompt(db_labeled, label)
+ try:
+ llm_prompts_label_hypercache.set_cache_value_redis_only(label_key, labeled_prompt)
+ except Exception as err:
+ capture_exception(err)
+
+ return strip_internal_metadata(merge_prompt_version_history_metadata(labeled_prompt, latest_prompt))
+
if version is None or version == latest_prompt["latest_version"]:
return strip_internal_metadata(latest_prompt)
@@ -147,6 +218,10 @@ def invalidate_prompt_version_cache(team: Team | str | int, prompt_name: str, ve
llm_prompts_hypercache.clear_cache(prompt_version_cache_key(team, prompt_name, version))
+def invalidate_prompt_label_cache(team: Team | str | int, prompt_name: str, label_name: str) -> None:
+ llm_prompts_label_hypercache.clear_cache(prompt_label_cache_key(team, prompt_name, label_name))
+
+
def invalidate_prompt_version_caches(team: Team | str | int, prompt_name: str, versions: Iterable[int]) -> None:
for version in versions:
invalidate_prompt_version_cache(team, prompt_name, int(version))
diff --git a/posthog/storage/llm_prompt_cache_keys.py b/posthog/storage/llm_prompt_cache_keys.py
index d5a0973a0fb2..90f9cbe1e9d1 100644
--- a/posthog/storage/llm_prompt_cache_keys.py
+++ b/posthog/storage/llm_prompt_cache_keys.py
@@ -15,7 +15,17 @@ def prompt_version_cache_key(team: Team | str | int, prompt_name: str, version:
return f"{_prompt_cache_key_prefix(team, prompt_name)}:v:{version}"
-def parse_prompt_cache_key(cache_key: KeyType) -> tuple[int, str, int | None] | None:
+def prompt_label_cache_key(team: Team | str | int, prompt_name: str, label_name: str) -> str:
+ # Prompt names and label names both forbid ":", so splitting on it stays unambiguous.
+ return f"{_prompt_cache_key_prefix(team, prompt_name)}:label:{label_name}"
+
+
+def parse_prompt_cache_key(cache_key: KeyType) -> tuple[int, str, int | None, str | None] | None:
+ """Parse a prompt cache key into (team_id, prompt_name, version, label).
+
+ Latest keys have version=None and label=None; version and label keys carry
+ exactly one of the two.
+ """
if not isinstance(cache_key, str):
return None
@@ -33,7 +43,7 @@ def parse_prompt_cache_key(cache_key: KeyType) -> tuple[int, str, int | None] |
return None
if len(parts) == 3 and parts[2] == "latest":
- return team_id, prompt_name, None
+ return team_id, prompt_name, None, None
if len(parts) == 4 and parts[2] == "v":
try:
@@ -42,6 +52,9 @@ def parse_prompt_cache_key(cache_key: KeyType) -> tuple[int, str, int | None] |
return None
if version < 1:
return None
- return team_id, prompt_name, version
+ return team_id, prompt_name, version, None
+
+ if len(parts) == 4 and parts[2] == "label" and parts[3]:
+ return team_id, prompt_name, None, parts[3]
return None
diff --git a/products/ai_observability/backend/models/llm_prompt.py b/products/ai_observability/backend/models/llm_prompt.py
index 91615b381c7a..44cffaa5e57c 100644
--- a/products/ai_observability/backend/models/llm_prompt.py
+++ b/products/ai_observability/backend/models/llm_prompt.py
@@ -160,3 +160,25 @@ def invalidate_llm_prompt_cache(sender: type[LLMPrompt], instance: LLMPrompt, **
capture_exception(err)
transaction.on_commit(clear_cache)
+
+
+@receiver(post_save, sender=LLMPromptLabel)
+@receiver(post_delete, sender=LLMPromptLabel)
+def invalidate_llm_prompt_label_cache(sender: type[LLMPromptLabel], instance: LLMPromptLabel, **kwargs) -> None:
+ # Label pointer changes never touch LLMPrompt rows, so the receiver above can't cover
+ # them — without this, a moved label would keep serving the old version from cache.
+ # post_save covers create (clears a cached 404 miss) and move; post_delete covers
+ # removal, including archive's queryset delete.
+ team_id = instance.team_id
+ prompt_name = instance.prompt_name
+ label_name = instance.name
+
+ def clear_cache() -> None:
+ from posthog.storage.llm_prompt_cache import invalidate_prompt_label_cache
+
+ try:
+ invalidate_prompt_label_cache(team_id, prompt_name, label_name)
+ except Exception as err:
+ capture_exception(err)
+
+ transaction.on_commit(clear_cache)
diff --git a/products/ai_observability/frontend/generated/api.schemas.ts b/products/ai_observability/frontend/generated/api.schemas.ts
index 9ab0f7b087cb..cb19a263c5cf 100644
--- a/products/ai_observability/frontend/generated/api.schemas.ts
+++ b/products/ai_observability/frontend/generated/api.schemas.ts
@@ -2218,6 +2218,8 @@ export interface LLMPromptPublicApi {
/** Flat list of markdown headings parsed from the prompt. Useful as a lightweight table of contents. */
outline: LLMPromptOutlineEntryApi[]
version: number
+ /** The label this prompt was fetched by. Only present when fetching with the label parameter. */
+ label?: string
created_at: string
updated_at: string
deleted: boolean
@@ -2976,6 +2978,12 @@ export type LlmPromptsNameRetrieveParams = {
* @minLength 1
*/
content?: LlmPromptsNameRetrieveContent
+ /**
+ * Fetch the version this label currently points to, e.g. 'production'. Lowercase letters, numbers, dots, hyphens and underscores. Mutually exclusive with version.
+ * @minLength 1
+ * @maxLength 128
+ */
+ label?: string
/**
* Specific prompt version to fetch. If omitted, the latest version is returned.
* @minimum 1
diff --git a/products/ai_observability/mcp/tools.yaml b/products/ai_observability/mcp/tools.yaml
index c5209ea1a622..670f92e801bd 100644
--- a/products/ai_observability/mcp/tools.yaml
+++ b/products/ai_observability/mcp/tools.yaml
@@ -518,6 +518,8 @@ tools:
title: Get prompt
description: |
Get a specific LLM prompt by name. Uses the cached endpoint for fast retrieval.
+ Pass `label` (e.g. 'production') to fetch the version that label currently points to, or `version` for an
+ exact version number — not both. With neither, the latest version is returned.
The response always includes `outline`, a flat list of markdown headings parsed from the prompt — useful
as a lightweight table of contents. Pass `content=none` to get the outline without the prompt payload,
or `content=preview` for a short `prompt_preview` snippet instead of the full prompt.
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index cb1ca8f38713..84fc6a761981 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -5095,7 +5095,7 @@
}
},
"llma-prompt-get": {
- "description": "Get a specific LLM prompt by name. Uses the cached endpoint for fast retrieval.\nThe response always includes `outline`, a flat list of markdown headings parsed from the prompt — useful\nas a lightweight table of contents. Pass `content=none` to get the outline without the prompt payload,\nor `content=preview` for a short `prompt_preview` snippet instead of the full prompt.",
+ "description": "Get a specific LLM prompt by name. Uses the cached endpoint for fast retrieval.\nPass `label` (e.g. 'production') to fetch the version that label currently points to, or `version` for an\nexact version number — not both. With neither, the latest version is returned.\nThe response always includes `outline`, a flat list of markdown headings parsed from the prompt — useful\nas a lightweight table of contents. Pass `content=none` to get the outline without the prompt payload,\nor `content=preview` for a short `prompt_preview` snippet instead of the full prompt.",
"category": "AI observability",
"feature": "llm_analytics",
"summary": "Get prompt",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 35f18eea62fc..ed2e762c84d3 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -5390,7 +5390,7 @@
}
},
"llma-prompt-get": {
- "description": "Get a specific LLM prompt by name. Uses the cached endpoint for fast retrieval.\nThe response always includes `outline`, a flat list of markdown headings parsed from the prompt — useful\nas a lightweight table of contents. Pass `content=none` to get the outline without the prompt payload,\nor `content=preview` for a short `prompt_preview` snippet instead of the full prompt.",
+ "description": "Get a specific LLM prompt by name. Uses the cached endpoint for fast retrieval.\nPass `label` (e.g. 'production') to fetch the version that label currently points to, or `version` for an\nexact version number — not both. With neither, the latest version is returned.\nThe response always includes `outline`, a flat list of markdown headings parsed from the prompt — useful\nas a lightweight table of contents. Pass `content=none` to get the outline without the prompt payload,\nor `content=preview` for a short `prompt_preview` snippet instead of the full prompt.",
"category": "AI observability",
"feature": "llm_analytics",
"summary": "Get prompt",
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index c640d437fbbb..a5322b8dbd71 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -33158,6 +33158,8 @@ export namespace Schemas {
/** Flat list of markdown headings parsed from the prompt. Useful as a lightweight table of contents. */
outline: LLMPromptOutlineEntry[];
version: number;
+ /** The label this prompt was fetched by. Only present when fetching with the label parameter. */
+ label?: string;
created_at: string;
updated_at: string;
deleted: boolean;
@@ -68150,6 +68152,12 @@ export namespace Schemas {
* @minLength 1
*/
content?: EnvironmentsLlmPromptsNameRetrieveContent;
+ /**
+ * Fetch the version this label currently points to, e.g. 'production'. Lowercase letters, numbers, dots, hyphens and underscores. Mutually exclusive with version.
+ * @minLength 1
+ * @maxLength 128
+ */
+ label?: string;
/**
* Specific prompt version to fetch. If omitted, the latest version is returned.
* @minimum 1
@@ -75858,6 +75866,12 @@ export namespace Schemas {
* @minLength 1
*/
content?: LlmPromptsNameRetrieveContent;
+ /**
+ * Fetch the version this label currently points to, e.g. 'production'. Lowercase letters, numbers, dots, hyphens and underscores. Mutually exclusive with version.
+ * @minLength 1
+ * @maxLength 128
+ */
+ label?: string;
/**
* Specific prompt version to fetch. If omitted, the latest version is returned.
* @minimum 1
diff --git a/services/mcp/src/generated/ai_observability/api.ts b/services/mcp/src/generated/ai_observability/api.ts
index dab245368a91..087baa16ecb1 100644
--- a/services/mcp/src/generated/ai_observability/api.ts
+++ b/services/mcp/src/generated/ai_observability/api.ts
@@ -1614,6 +1614,7 @@ export const LlmPromptsNameRetrieveParams = /* @__PURE__ */ zod.object({
})
export const llmPromptsNameRetrieveQueryContentDefault = `full`
+export const llmPromptsNameRetrieveQueryLabelMax = 128
export const LlmPromptsNameRetrieveQueryParams = /* @__PURE__ */ zod.object({
content: zod
@@ -1622,6 +1623,14 @@ export const LlmPromptsNameRetrieveQueryParams = /* @__PURE__ */ zod.object({
.describe(
"Controls how much prompt content is included in the response. 'full' includes the full prompt, 'preview' includes a short prompt_preview, and 'none' omits prompt content entirely. The outline field is always included.\n\n* `full` - full\n* `preview` - preview\n* `none` - none"
),
+ label: zod
+ .string()
+ .min(1)
+ .max(llmPromptsNameRetrieveQueryLabelMax)
+ .optional()
+ .describe(
+ "Fetch the version this label currently points to, e.g. 'production'. Lowercase letters, numbers, dots, hyphens and underscores. Mutually exclusive with version."
+ ),
version: zod
.number()
.min(1)
diff --git a/services/mcp/src/tools/generated/ai_observability.ts b/services/mcp/src/tools/generated/ai_observability.ts
index 093a484b3d7e..e6554c360de3 100644
--- a/services/mcp/src/tools/generated/ai_observability.ts
+++ b/services/mcp/src/tools/generated/ai_observability.ts
@@ -798,6 +798,7 @@ const llmaPromptGet = (): ToolBase<typeof LlmaPromptGetSchema, Schemas.LLMPrompt
path: `/api/projects/${encodeURIComponent(String(projectId))}/llm_prompts/name/${encodeURIComponent(String(params.prompt_name))}/`,
query: {
content: params.content,
+ label: params.label,
version: params.version,
},
})
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-prompt-get.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-prompt-get.json
index 43672ccf7854..266a4feaa7a9 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-prompt-get.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-prompt-get.json
@@ -7,6 +7,12 @@
"enum": ["full", "preview", "none"],
"type": "string"
},
+ "label": {
+ "description": "Fetch the version this label currently points to, e.g. 'production'. Lowercase letters, numbers, dots, hyphens and underscores. Mutually exclusive with version.",
+ "maxLength": 128,
+ "minLength": 1,
+ "type": "string"
+ },
"prompt_name": {
"pattern": "^[^/]+$",
"type": "string"