: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(llma): redirect skill lookups by UUID to name-based URL (#58697)
Paul D'Ambrab7eec46cb376
diff --git a/products/llm_analytics/backend/api/skills.py b/products/llm_analytics/backend/api/skills.pyindex 1a05ecd9f455..695f77487093 100644--- a/products/llm_analytics/backend/api/skills.py+++ b/products/llm_analytics/backend/api/skills.py@@ -1,4 +1,5 @@from typing import Any, cast+from uuid import UUIDfrom django.db import IntegrityErrorfrom django.db.models import Q, QuerySet@@ -75,6 +76,14 @@ def _file_extension(path: str) -> str:return path.rsplit(".", 1)[1].lower() if "." in path else ""+def _is_uuid(value: str) -> bool:+ try:+ UUID(value)+ return True+ except ValueError:+ return False++def _skill_analytics_props(skill: LLMSkill) -> dict[str, Any]:"""Properties shared by every skill report_user_action event.@@ -295,23 +304,40 @@ class LLMSkillViewSet(parameters=[LLMSkillFetchQuerySerializer],responses={200: LLMSkillSerializer},)- @action(methods=["GET"], detail=False, url_path=r"name/(?P<skill_name>[^/]+)")+ @action(methods=["GET"], detail=False, url_path=r"name/(?P<skill_identifier>[^/]+)")@llma_track_latency("llma_skills_get_by_name")@monitor(feature=None, endpoint="llma_skills_get_by_name", method="GET")- def get_by_name(self, request: Request, skill_name: str = "", **kwargs) -> Response:+ def get_by_name(self, request: Request, skill_identifier: str = "", **kwargs) -> Response:version_params = self._get_requested_version_params(request)version = cast(int | None, version_params.get("version"))- skill = get_skill_by_name_from_db(self.team, skill_name, version)+ skill = get_skill_by_name_from_db(self.team, skill_identifier, version)++ if skill is None and _is_uuid(skill_identifier):+ redirect = self._redirect_to_name(request, skill_identifier)+ if redirect is not None:+ return redirect+if skill is None:- return self._skill_not_found_response(skill_name)+ return self._skill_not_found_response(skill_identifier)return Response(self._serialize_skill(skill))+ def _redirect_to_name(self, request: Request, skill_identifier: str) -> Response | None:+ skill_by_id = get_active_skill_queryset(self.team).filter(id=skill_identifier).first()+ if skill_by_id is None:+ return None+ # Use a relative path (no build_absolute_uri) to avoid embedding the+ # Host header in the Location value — prevents host-header open-redirect.+ redirect_url = request.get_full_path().replace(skill_identifier, skill_by_id.name, 1)+ response = Response(status=status.HTTP_302_FOUND)+ response["Location"] = redirect_url+ return response+@extend_schema(request=LLMSkillPublishSerializer, responses={200: LLMSkillSerializer})@get_by_name.mapping.patch@llma_track_latency("llma_skills_publish_by_name")@monitor(feature=None, endpoint="llma_skills_publish_by_name", method="PATCH")- def update_by_name(self, request: Request, skill_name: str = "", **kwargs) -> Response:+ def update_by_name(self, request: Request, skill_identifier: str = "", **kwargs) -> Response:auth_error = self._ensure_web_authenticated(request)if auth_error is not None:return auth_error@@ -323,7 +349,7 @@ class LLMSkillViewSet(published_skill = publish_skill_version(self.team,user=cast(User, request.user),- skill_name=skill_name,+ skill_name=skill_identifier,body=payload.validated_data.get("body"),edits=payload.validated_data.get("edits"),description=payload.validated_data.get("description"),@@ -340,7 +366,7 @@ class LLMSkillViewSet(raise serializers.ValidationError({"files": "Duplicate file paths are not allowed."}, code="unique")raiseexcept LLMSkillNotFoundError:- return self._skill_not_found_response(skill_name)+ return self._skill_not_found_response(skill_identifier)except LLMSkillVersionConflictError as err:return Response({diff --git a/products/llm_analytics/backend/api/test/test_skills.py b/products/llm_analytics/backend/api/test/test_skills.pyindex ce9ccc8fa74b..3e59acc559f3 100644--- a/products/llm_analytics/backend/api/test/test_skills.py+++ b/products/llm_analytics/backend/api/test/test_skills.py@@ -320,6 +320,41 @@ class TestLLMSkillAPI(APIBaseTest):assert response.status_code == status.HTTP_404_NOT_FOUND+ @parameterized.expand(+ [+ ("no_query_string", "", None),+ ("with_version_query_string", "?version=1", 1),+ ]+ )+ def test_get_skill_by_uuid_redirects_to_name(self, mock_feature_enabled, _label, query_suffix, _version):+ skill = self.create_skill(name="uuid-redirect-target")+ skill_id = str(skill.id)++ response = self.client.get(self._url(f"name/{skill_id}{query_suffix}"))++ assert response.status_code == status.HTTP_302_FOUND+ assert "uuid-redirect-target" in response["Location"]+ assert skill_id not in response["Location"]+ if query_suffix:+ assert query_suffix.lstrip("?") in response["Location"]++ def test_get_skill_by_uuid_not_found_returns_404(self, mock_feature_enabled):+ import uuid++ nonexistent_id = str(uuid.uuid4())+ response = self.client.get(self._url(f"name/{nonexistent_id}"))++ assert response.status_code == status.HTTP_404_NOT_FOUND++ def test_get_skill_with_uuid_shaped_name_returns_skill_not_redirect(self, mock_feature_enabled):+ uuid_shaped_name = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"+ self.create_skill(name=uuid_shaped_name, body="# UUID-named skill")++ response = self.client.get(self._url(f"name/{uuid_shaped_name}"))++ assert response.status_code == status.HTTP_200_OK+ assert response.json()["name"] == uuid_shaped_name+# --- Publish new version ---def test_publish_new_version(self, mock_feature_enabled):diff --git a/products/llm_analytics/frontend/generated/api.ts b/products/llm_analytics/frontend/generated/api.tsindex dc9f2a9b7be3..2c74e1fec32a 100644--- a/products/llm_analytics/frontend/generated/api.ts+++ b/products/llm_analytics/frontend/generated/api.ts@@ -1752,7 +1752,7 @@ export const llmSkillsCreate = async (export const getLlmSkillsNameRetrieveUrl = (projectId: string,- skillName: string,+ skillIdentifier: string,params?: LlmSkillsNameRetrieveParams) => {const normalizedParams = new URLSearchParams()@@ -1766,33 +1766,33 @@ export const getLlmSkillsNameRetrieveUrl = (const stringifiedParams = normalizedParams.toString()return stringifiedParams.length > 0- ? `/api/environments/${projectId}/llm_skills/name/${skillName}/?${stringifiedParams}`- : `/api/environments/${projectId}/llm_skills/name/${skillName}/`+ ? `/api/environments/${projectId}/llm_skills/name/${skillIdentifier}/?${stringifiedParams}`+ : `/api/environments/${projectId}/llm_skills/name/${skillIdentifier}/`}export const llmSkillsNameRetrieve = async (projectId: string,- skillName: string,+ skillIdentifier: string,params?: LlmSkillsNameRetrieveParams,options?: RequestInit): Promise<LLMSkillApi> => {- return apiMutator<LLMSkillApi>(getLlmSkillsNameRetrieveUrl(projectId, skillName, params), {+ return apiMutator<LLMSkillApi>(getLlmSkillsNameRetrieveUrl(projectId, skillIdentifier, params), {...options,method: 'GET',})}-export const getLlmSkillsNamePartialUpdateUrl = (projectId: string, skillName: string) => {- return `/api/environments/${projectId}/llm_skills/name/${skillName}/`+export const getLlmSkillsNamePartialUpdateUrl = (projectId: string, skillIdentifier: string) => {+ return `/api/environments/${projectId}/llm_skills/name/${skillIdentifier}/`}export const llmSkillsNamePartialUpdate = async (projectId: string,- skillName: string,+ skillIdentifier: string,patchedLLMSkillPublishApi?: PatchedLLMSkillPublishApi,options?: RequestInit): Promise<LLMSkillApi> => {- return apiMutator<LLMSkillApi>(getLlmSkillsNamePartialUpdateUrl(projectId, skillName), {+ return apiMutator<LLMSkillApi>(getLlmSkillsNamePartialUpdateUrl(projectId, skillIdentifier), {...options,method: 'PATCH',headers: { 'Content-Type': 'application/json', ...options?.headers },diff --git a/services/mcp/src/generated/llm_analytics/api.ts b/services/mcp/src/generated/llm_analytics/api.tsindex 02c77567df2c..a1ebc3b5981a 100644--- a/services/mcp/src/generated/llm_analytics/api.ts+++ b/services/mcp/src/generated/llm_analytics/api.ts@@ -1510,7 +1510,7 @@ export const LlmSkillsCreateBody = /* @__PURE__ */ zod}).describe('Create serializer — accepts bundled files as write-only input on POST.')-export const llmSkillsNameRetrievePathSkillNameRegExp = new RegExp('^[^/]+$')+export const llmSkillsNameRetrievePathSkillIdentifierRegExp = new RegExp('^[^/]+$')export const LlmSkillsNameRetrieveParams = /* @__PURE__ */ zod.object({project_id: zod@@ -1518,7 +1518,7 @@ export const LlmSkillsNameRetrieveParams = /* @__PURE__ */ zod.object({.describe("Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."),- skill_name: zod.string().regex(llmSkillsNameRetrievePathSkillNameRegExp),+ skill_identifier: zod.string().regex(llmSkillsNameRetrievePathSkillIdentifierRegExp),})export const LlmSkillsNameRetrieveQueryParams = /* @__PURE__ */ zod.object({@@ -1529,7 +1529,7 @@ export const LlmSkillsNameRetrieveQueryParams = /* @__PURE__ */ zod.object({.describe('Specific skill version to fetch. If omitted, the latest version is returned.'),})-export const llmSkillsNamePartialUpdatePathSkillNameRegExp = new RegExp('^[^/]+$')+export const llmSkillsNamePartialUpdatePathSkillIdentifierRegExp = new RegExp('^[^/]+$')export const LlmSkillsNamePartialUpdateParams = /* @__PURE__ */ zod.object({project_id: zod@@ -1537,7 +1537,7 @@ export const LlmSkillsNamePartialUpdateParams = /* @__PURE__ */ zod.object({.describe("Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."),- skill_name: zod.string().regex(llmSkillsNamePartialUpdatePathSkillNameRegExp),+ skill_identifier: zod.string().regex(llmSkillsNamePartialUpdatePathSkillIdentifierRegExp),})export const llmSkillsNamePartialUpdateBodyDescriptionMax = 4096diff --git a/services/mcp/src/tools/generated/llm_analytics.ts b/services/mcp/src/tools/generated/llm_analytics.tsindex f6a3ee3c35a1..b26c61459137 100644--- a/services/mcp/src/tools/generated/llm_analytics.ts+++ b/services/mcp/src/tools/generated/llm_analytics.ts@@ -1365,7 +1365,7 @@ const llmaSkillGet = (): ToolBase<typeof LlmaSkillGetSchema, Schemas.LLMSkill> =const projectId = await context.stateManager.getProjectId()const result = await context.api.request<Schemas.LLMSkill>({method: 'GET',- path: `/api/environments/${encodeURIComponent(String(projectId))}/llm_skills/name/${encodeURIComponent(String(params.skill_name))}/`,+ path: `/api/environments/${encodeURIComponent(String(projectId))}/llm_skills/name/${encodeURIComponent(String(params.skill_identifier))}/`,query: {version: params.version,},@@ -1437,7 +1437,7 @@ const llmaSkillUpdate = (): ToolBase<typeof LlmaSkillUpdateSchema, Schemas.LLMSk}const result = await context.api.request<Schemas.LLMSkill>({method: 'PATCH',- path: `/api/environments/${encodeURIComponent(String(projectId))}/llm_skills/name/${encodeURIComponent(String(params.skill_name))}/`,+ path: `/api/environments/${encodeURIComponent(String(projectId))}/llm_skills/name/${encodeURIComponent(String(params.skill_identifier))}/`,body,})return resultdiff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/llma-skill-get.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/llma-skill-get.jsonindex ed1bb018c7d8..ecde453f3fb0 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/llma-skill-get.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/llma-skill-get.json@@ -1,7 +1,7 @@{"$schema": "https://json-schema.org/draft/2020-12/schema","properties": {- "skill_name": {+ "skill_identifier": {"pattern": "^[^/]+$","type": "string"},@@ -11,6 +11,6 @@"type": "number"}},- "required": ["skill_name"],+ "required": ["skill_identifier"],"type": "object"}diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/llma-skill-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/llma-skill-update.jsonindex ccab96beb18b..498a37d937d2 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/llma-skill-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/llma-skill-update.json@@ -116,11 +116,11 @@},"type": "object"},- "skill_name": {+ "skill_identifier": {"pattern": "^[^/]+$","type": "string"}},- "required": ["skill_name"],+ "required": ["skill_identifier"],"type": "object"}