: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
feat(llma): accept a version description when publishing prompts (#69156)
Juraj Majerik1ecc1e146d35
diff --git a/posthog/api/llm_prompt.py b/posthog/api/llm_prompt.pyindex 1d621a0edcf3..d74d7cca6f63 100644--- a/posthog/api/llm_prompt.py+++ b/posthog/api/llm_prompt.py@@ -290,6 +290,7 @@ class LLMPromptViewSet(prompt_payload=payload.validated_data.get("prompt"),edits=payload.validated_data.get("edits"),base_version=payload.validated_data["base_version"],+ version_description=payload.validated_data.get("version_description"),)except LLMPromptNotFoundError:return self._prompt_not_found_response(prompt_name)diff --git a/posthog/api/llm_prompt_serializers.py b/posthog/api/llm_prompt_serializers.pyindex 7323ecf5a931..ac1890e51439 100644--- a/posthog/api/llm_prompt_serializers.py+++ b/posthog/api/llm_prompt_serializers.py@@ -147,10 +147,19 @@ class LLMPromptPublishSerializer(serializers.Serializer):min_value=1,help_text="Latest version you are editing from. Used for optimistic concurrency checks.",)+ version_description = serializers.CharField(+ max_length=400,+ required=False,+ allow_blank=True,+ help_text="Optional note describing what changed in this version. Shown in the version history.",+ )def validate_prompt(self, value: Any) -> Any:return validate_prompt_payload_size(value)+ def validate_version_description(self, value: str) -> str | None:+ return value.strip() or None+def validate_edits(self, value: list[dict[str, str]]) -> list[dict[str, str]]:if len(value) == 0:raise serializers.ValidationError("At least one edit operation is required.")@@ -183,6 +192,7 @@ class LLMPromptSerializer(serializers.ModelSerializer):"name","prompt","version",+ "version_description","created_by","created_at","updated_at",@@ -209,6 +219,9 @@ class LLMPromptSerializer(serializers.ModelSerializer):extra_kwargs = {"name": {"help_text": "Unique prompt name using letters, numbers, hyphens, and underscores only."},"prompt": {"help_text": "Prompt payload as JSON or string data."},+ "version_description": {+ "help_text": "Optional note describing what changed in this version. Set when the version is published."+ },}@extend_schema_field(LLMPromptOutlineEntrySerializer(many=True))@@ -244,6 +257,11 @@ class LLMPromptSerializer(serializers.ModelSerializer):def validate_prompt(self, value: Any) -> Any:return validate_prompt_payload_size(value)+ def validate_version_description(self, value: str | None) -> str | None:+ if value is None:+ return None+ return value.strip() or None+def validate(self, attrs: dict[str, Any]) -> dict[str, Any]:team = self.context["get_team"]()name = attrs.get("name")@@ -316,6 +334,7 @@ class LLMPromptVersionSummarySerializer(serializers.ModelSerializer):fields = ["id","version",+ "version_description","created_by","created_at","is_latest",diff --git a/posthog/api/services/llm_prompt.py b/posthog/api/services/llm_prompt.pyindex 15d3b4f35523..f0ee4554ee74 100644--- a/posthog/api/services/llm_prompt.py+++ b/posthog/api/services/llm_prompt.py@@ -147,6 +147,7 @@ def publish_prompt_version(prompt_payload: Any | None = None,edits: list[dict[str, str]] | None = None,base_version: int,+ version_description: str | None = None,) -> LLMPrompt:with transaction.atomic():current_latest = (@@ -176,6 +177,7 @@ def publish_prompt_version(version=current_latest.version + 1,is_latest=True,created_by=user,+ version_description=version_description,)refreshed_prompt = (diff --git a/posthog/api/test/test_llm_prompt.py b/posthog/api/test/test_llm_prompt.pyindex 5f9f06aa7d30..e7518e5683fb 100644--- a/posthog/api/test/test_llm_prompt.py+++ b/posthog/api/test/test_llm_prompt.py@@ -43,6 +43,7 @@ class TestLLMPromptAPI(APIBaseTest):data={"name": "my-prompt","prompt": "You are a helpful assistant.",+ "version_description": "Initial version",},format="json",)@@ -52,6 +53,7 @@ class TestLLMPromptAPI(APIBaseTest):assert response.json()["is_latest"] is Trueassert response.json()["latest_version"] == 1assert response.json()["version_count"] == 1+ assert response.json()["version_description"] == "Initial version"def test_create_prompt_with_duplicate_active_name_fails(self):self.create_prompt_version(name="my-prompt")@@ -344,6 +346,23 @@ class TestLLMPromptAPI(APIBaseTest):assert response.json()["latest_version"] == 2assert response.json()["version_count"] == 2+ def test_publish_persists_version_description_and_returns_it_in_version_summaries(self):+ self.create_prompt_version(name="publish-prompt", version=1, is_latest=True, prompt="v1")++ response = self.client.patch(+ f"/api/environments/{self.team.id}/llm_prompts/name/publish-prompt/",+ data={"prompt": "v2", "base_version": 1, "version_description": "Tightened the refusal criteria"},+ format="json",+ )++ assert response.status_code == status.HTTP_200_OK+ assert response.json()["version_description"] == "Tightened the refusal criteria"++ resolve_response = self.client.get(f"/api/environments/{self.team.id}/llm_prompts/resolve/name/publish-prompt/")+ assert resolve_response.status_code == status.HTTP_200_OK+ versions = resolve_response.json()["versions"]+ assert [v["version_description"] for v in versions] == ["Tightened the refusal criteria", None]+def test_update_prompt_by_name_falls_back_when_post_publish_refresh_misses_row(self):first_version = self.create_prompt_version(name="publish-prompt", version=1, is_latest=True, prompt="v1")diff --git a/products/ai_observability/backend/migrations/0015_llmprompt_version_description.py b/products/ai_observability/backend/migrations/0015_llmprompt_version_description.pynew file mode 100644index 000000000000..c4ebdd7ee246--- /dev/null+++ b/products/ai_observability/backend/migrations/0015_llmprompt_version_description.py@@ -0,0 +1,17 @@+# Generated by Django 5.2.14 on 2026-07-08 04:39++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("ai_observability", "0014_validate_model_config_only_on_llm_judge"),+ ]++ operations = [+ migrations.AddField(+ model_name="llmprompt",+ name="version_description",+ field=models.CharField(blank=True, max_length=400, null=True),+ ),+ ]diff --git a/products/ai_observability/backend/migrations/max_migration.txt b/products/ai_observability/backend/migrations/max_migration.txtindex d53db48043c3..6e9dbdb0d51f 100644--- a/products/ai_observability/backend/migrations/max_migration.txt+++ b/products/ai_observability/backend/migrations/max_migration.txt@@ -1 +1 @@-0014_validate_model_config_only_on_llm_judge+0015_llmprompt_version_descriptiondiff --git a/products/ai_observability/backend/models/llm_prompt.py b/products/ai_observability/backend/models/llm_prompt.pyindex 09e26d734f79..87c7dddfeaba 100644--- a/products/ai_observability/backend/models/llm_prompt.py+++ b/products/ai_observability/backend/models/llm_prompt.py@@ -57,6 +57,9 @@ class LLMPrompt(UUIDModel):version = models.PositiveIntegerField(default=1)is_latest = models.BooleanField(default=True)+ # Optional "what changed" note set when the version is published; immutable like the rest of the row+ version_description = models.CharField(max_length=400, null=True, blank=True)+team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE)created_by = models.ForeignKey("posthog.User",diff --git a/products/ai_observability/frontend/generated/api.schemas.ts b/products/ai_observability/frontend/generated/api.schemas.tsindex 3e3c6860232e..545d7b05cb24 100644--- a/products/ai_observability/frontend/generated/api.schemas.ts+++ b/products/ai_observability/frontend/generated/api.schemas.ts@@ -1952,6 +1952,11 @@ export interface LLMPromptListApi {/** Prompt payload as JSON or string data. */readonly prompt: unknownreadonly version: number+ /**+ * Optional note describing what changed in this version. Set when the version is published.+ * @nullable+ */+ readonly version_description: string | nullreadonly created_by: UserBasicApireadonly created_at: stringreadonly updated_at: string@@ -1984,6 +1989,12 @@ export interface LLMPromptApi {/** Prompt payload as JSON or string data. */prompt: unknownreadonly version: number+ /**+ * Optional note describing what changed in this version. Set when the version is published.+ * @maxLength 400+ * @nullable+ */+ version_description?: string | nullreadonly created_by: UserBasicApireadonly created_at: stringreadonly updated_at: string@@ -2031,6 +2042,11 @@ export interface PatchedLLMPromptPublishApi {* @minimum 1*/base_version?: number+ /**+ * Optional note describing what changed in this version. Shown in the version history.+ * @maxLength 400+ */+ version_description?: string}export interface LLMPromptDuplicateApi {@@ -2044,6 +2060,8 @@ export interface LLMPromptDuplicateApi {export interface LLMPromptVersionSummaryApi {readonly id: stringreadonly version: number+ /** @nullable */+ readonly version_description: string | nullreadonly created_by: UserBasicApireadonly created_at: stringreadonly is_latest: booleandiff --git a/products/ai_observability/frontend/generated/api.zod.ts b/products/ai_observability/frontend/generated/api.zod.tsindex 52faa9145350..52d03285c87e 100644--- a/products/ai_observability/frontend/generated/api.zod.ts+++ b/products/ai_observability/frontend/generated/api.zod.ts@@ -1745,14 +1745,23 @@ export const LlmAnalyticsTranslateCreateBody = /* @__PURE__ */ zod.object({export const llmPromptsCreateBodyNameMax = 255+export const llmPromptsCreateBodyVersionDescriptionMax = 400+export const LlmPromptsCreateBody = /* @__PURE__ */ zod.object({name: zod.string().max(llmPromptsCreateBodyNameMax).describe('Unique prompt name using letters, numbers, hyphens, and underscores only.'),prompt: zod.unknown().describe('Prompt payload as JSON or string data.'),+ version_description: zod+ .string()+ .max(llmPromptsCreateBodyVersionDescriptionMax)+ .nullish()+ .describe('Optional note describing what changed in this version. Set when the version is published.'),})+export const llmPromptsNamePartialUpdateBodyVersionDescriptionMax = 400+export const LlmPromptsNamePartialUpdateBody = /* @__PURE__ */ zod.object({prompt: zod.unknown()@@ -1774,16 +1783,28 @@ export const LlmPromptsNamePartialUpdateBody = /* @__PURE__ */ zod.object({.min(1).optional().describe('Latest version you are editing from. Used for optimistic concurrency checks.'),+ version_description: zod+ .string()+ .max(llmPromptsNamePartialUpdateBodyVersionDescriptionMax)+ .optional()+ .describe('Optional note describing what changed in this version. Shown in the version history.'),})export const llmPromptsNameArchiveCreateBodyNameMax = 255+export const llmPromptsNameArchiveCreateBodyVersionDescriptionMax = 400+export const LlmPromptsNameArchiveCreateBody = /* @__PURE__ */ zod.object({name: zod.string().max(llmPromptsNameArchiveCreateBodyNameMax).describe('Unique prompt name using letters, numbers, hyphens, and underscores only.'),prompt: zod.unknown().describe('Prompt payload as JSON or string data.'),+ version_description: zod+ .string()+ .max(llmPromptsNameArchiveCreateBodyVersionDescriptionMax)+ .nullish()+ .describe('Optional note describing what changed in this version. Set when the version is published.'),})export const llmPromptsNameDuplicateCreateBodyNewNameMax = 255diff --git a/products/ai_observability/mcp/tools.yaml b/products/ai_observability/mcp/tools.yamlindex b9f2f2e95e51..e6906126f758 100644--- a/products/ai_observability/mcp/tools.yaml+++ b/products/ai_observability/mcp/tools.yaml@@ -503,6 +503,7 @@ tools:include_params:- name- prompt+ - version_descriptionllma-prompt-duplicate:operation: llm_prompts_name_duplicate_createenabled: true@@ -570,11 +571,13 @@ tools:You can either provide the full prompt content via 'prompt', or use 'edits' for incrementalfind/replace updates. Each edit must have 'old' (text to find, must match exactly once) and'new' (replacement text). Edits are applied sequentially. Only one of 'prompt' or 'edits'- may be provided.+ may be provided. Pass 'version_description' with a short note on what changed and why —+ it is shown in the prompt's version history.include_params:- prompt- edits- base_version+ - version_descriptionllma-provider-key-assign:operation: llm_analytics_provider_keys_assign_createenabled: falsediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex dbf99136325f..d05836004c53 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -4891,7 +4891,7 @@}},"llma-prompt-update": {- "description": "Publish a new version of an existing LLM prompt by name. Name is immutable after creation.\nYou can either provide the full prompt content via 'prompt', or use 'edits' for incremental\nfind/replace updates. Each edit must have 'old' (text to find, must match exactly once) and\n'new' (replacement text). Edits are applied sequentially. Only one of 'prompt' or 'edits'\nmay be provided.",+ "description": "Publish a new version of an existing LLM prompt by name. Name is immutable after creation.\nYou can either provide the full prompt content via 'prompt', or use 'edits' for incremental\nfind/replace updates. Each edit must have 'old' (text to find, must match exactly once) and\n'new' (replacement text). Edits are applied sequentially. Only one of 'prompt' or 'edits'\nmay be provided. Pass 'version_description' with a short note on what changed and why —\nit is shown in the prompt's version history.","category": "AI observability","feature": "llm_analytics","summary": "Update prompt",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex a55ff5866f8f..33731f1d1e0f 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -5187,7 +5187,7 @@}},"llma-prompt-update": {- "description": "Publish a new version of an existing LLM prompt by name. Name is immutable after creation.\nYou can either provide the full prompt content via 'prompt', or use 'edits' for incremental\nfind/replace updates. Each edit must have 'old' (text to find, must match exactly once) and\n'new' (replacement text). Edits are applied sequentially. Only one of 'prompt' or 'edits'\nmay be provided.",+ "description": "Publish a new version of an existing LLM prompt by name. Name is immutable after creation.\nYou can either provide the full prompt content via 'prompt', or use 'edits' for incremental\nfind/replace updates. Each edit must have 'old' (text to find, must match exactly once) and\n'new' (replacement text). Edits are applied sequentially. Only one of 'prompt' or 'edits'\nmay be provided. Pass 'version_description' with a short note on what changed and why —\nit is shown in the prompt's version history.","category": "AI observability","feature": "llm_analytics","summary": "Update prompt",diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 281bddfbb18c..02e35b872e4b 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -28880,6 +28880,12 @@ export namespace Schemas {/** Prompt payload as JSON or string data. */prompt: unknown;readonly version: number;+ /**+ * Optional note describing what changed in this version. Set when the version is published.+ * @maxLength 400+ * @nullable+ */+ version_description?: string | null;readonly created_by: UserBasic;readonly created_at: string;readonly updated_at: string;@@ -28913,6 +28919,11 @@ export namespace Schemas {/** Prompt payload as JSON or string data. */readonly prompt: unknown;readonly version: number;+ /**+ * Optional note describing what changed in this version. Set when the version is published.+ * @nullable+ */+ readonly version_description: string | null;readonly created_by: UserBasic;readonly created_at: string;readonly updated_at: string;@@ -28948,6 +28959,8 @@ export namespace Schemas {export interface LLMPromptVersionSummary {readonly id: string;readonly version: number;+ /** @nullable */+ readonly version_description: string | null;readonly created_by: UserBasic;readonly created_at: string;readonly is_latest: boolean;@@ -39693,6 +39706,11 @@ export namespace Schemas {* @minimum 1*/base_version?: number;+ /**+ * Optional note describing what changed in this version. Shown in the version history.+ * @maxLength 400+ */+ version_description?: string;}export interface PatchedLLMProviderKey {diff --git a/services/mcp/src/generated/ai_observability/api.ts b/services/mcp/src/generated/ai_observability/api.tsindex 386630f23704..aa1c8529cee8 100644--- a/services/mcp/src/generated/ai_observability/api.ts+++ b/services/mcp/src/generated/ai_observability/api.ts@@ -1607,12 +1607,19 @@ export const LlmPromptsCreateParams = /* @__PURE__ */ zod.object({export const llmPromptsCreateBodyNameMax = 255+export const llmPromptsCreateBodyVersionDescriptionMax = 400+export const LlmPromptsCreateBody = /* @__PURE__ */ zod.object({name: zod.string().max(llmPromptsCreateBodyNameMax).describe('Unique prompt name using letters, numbers, hyphens, and underscores only.'),prompt: zod.unknown().describe('Prompt payload as JSON or string data.'),+ version_description: zod+ .string()+ .max(llmPromptsCreateBodyVersionDescriptionMax)+ .nullish()+ .describe('Optional note describing what changed in this version. Set when the version is published.'),})export const llmPromptsNameRetrievePathPromptNameRegExp = new RegExp('^[^/]+$')@@ -1653,6 +1660,8 @@ export const LlmPromptsNamePartialUpdateParams = /* @__PURE__ */ zod.object({prompt_name: zod.string().regex(llmPromptsNamePartialUpdatePathPromptNameRegExp),})+export const llmPromptsNamePartialUpdateBodyVersionDescriptionMax = 400+export const LlmPromptsNamePartialUpdateBody = /* @__PURE__ */ zod.object({prompt: zod.unknown()@@ -1674,6 +1683,11 @@ export const LlmPromptsNamePartialUpdateBody = /* @__PURE__ */ zod.object({.min(1).optional().describe('Latest version you are editing from. Used for optimistic concurrency checks.'),+ version_description: zod+ .string()+ .max(llmPromptsNamePartialUpdateBodyVersionDescriptionMax)+ .optional()+ .describe('Optional note describing what changed in this version. Shown in the version history.'),})export const llmPromptsNameDuplicateCreatePathPromptNameRegExp = new RegExp('^[^/]+$')diff --git a/services/mcp/src/tools/generated/ai_observability.ts b/services/mcp/src/tools/generated/ai_observability.tsindex f9718fca9e15..a7f4b048be5e 100644--- a/services/mcp/src/tools/generated/ai_observability.ts+++ b/services/mcp/src/tools/generated/ai_observability.ts@@ -777,6 +777,9 @@ const llmaPromptCreate = (): ToolBase<typeof LlmaPromptCreateSchema, Schemas.LLMif (params.prompt !== undefined) {body['prompt'] = params.prompt}+ if (params.version_description !== undefined) {+ body['version_description'] = params.version_description+ }const result = await context.api.request<Schemas.LLMPrompt>({method: 'POST',path: `/api/projects/${encodeURIComponent(String(projectId))}/llm_prompts/`,@@ -874,6 +877,9 @@ const llmaPromptUpdate = (): ToolBase<typeof LlmaPromptUpdateSchema, Schemas.LLMif (params.base_version !== undefined) {body['base_version'] = params.base_version}+ if (params.version_description !== undefined) {+ body['version_description'] = params.version_description+ }const result = await context.api.request<Schemas.LLMPrompt>({method: 'PATCH',path: `/api/projects/${encodeURIComponent(String(projectId))}/llm_prompts/name/${encodeURIComponent(String(params.prompt_name))}/`,diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-prompt-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-prompt-create.jsonindex 915195509d64..484400a32088 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-prompt-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-prompt-create.json@@ -8,6 +8,18 @@},"prompt": {"description": "Prompt payload as JSON or string data."+ },+ "version_description": {+ "anyOf": [+ {+ "maxLength": 400,+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "description": "Optional note describing what changed in this version. Set when the version is published."}},"required": ["name", "prompt"],diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-prompt-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-prompt-update.jsonindex b108f21343dd..13257bd23f53 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-prompt-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-prompt-update.json@@ -30,6 +30,11 @@"prompt_name": {"pattern": "^[^/]+$","type": "string"+ },+ "version_description": {+ "description": "Optional note describing what changed in this version. Shown in the version history.",+ "maxLength": 400,+ "type": "string"}},"required": ["prompt_name"],