: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): surface server error details in prompt archive and duplicate toasts (#68641)
Juraj Majerik7f315020e516
diff --git a/products/ai_observability/frontend/playground/llmPlaygroundPromptsLogic.ts b/products/ai_observability/frontend/playground/llmPlaygroundPromptsLogic.tsindex b3c0ea0e1c2f..a24adf36ee45 100644--- a/products/ai_observability/frontend/playground/llmPlaygroundPromptsLogic.ts+++ b/products/ai_observability/frontend/playground/llmPlaygroundPromptsLogic.ts@@ -13,7 +13,8 @@ import { urls } from 'scenes/urls'import { llmEvaluationLogic } from '../evaluations/llmEvaluationLogic'import type { EvaluationConfig } from '../evaluations/types'import { normalizeMessage } from '../messageNormalization'-import { getApiErrorDetail, llmPromptLogic } from '../prompts/llmPromptLogic'+import { llmPromptLogic } from '../prompts/llmPromptLogic'+import { getApiErrorDetail } from '../prompts/utils'import { normalizeLLMProvider } from '../settings/llmProviderKeysLogic'import { isOTelPartsMessage, normalizeRole, safeStringify } from '../utils'import type { llmPlaygroundPromptsLogicType } from './llmPlaygroundPromptsLogicType'diff --git a/products/ai_observability/frontend/prompts/LLMPromptsScene.tsx b/products/ai_observability/frontend/prompts/LLMPromptsScene.tsxindex 012825ed507b..e215086313d9 100644--- a/products/ai_observability/frontend/prompts/LLMPromptsScene.tsx+++ b/products/ai_observability/frontend/prompts/LLMPromptsScene.tsx@@ -23,7 +23,7 @@ import { ProductKey } from '~/queries/schema/schema-general'import { AccessControlLevel, AccessControlResourceType, LLMPrompt } from '~/types'import { PROMPTS_PER_PAGE, llmPromptsLogic } from './llmPromptsLogic'-import { openArchivePromptDialog } from './utils'+import { PROMPT_NAME_MAX_LENGTH, openArchivePromptDialog, validatePromptName } from './utils'export const scene: SceneExport = {component: LLMPromptsScene,@@ -117,17 +117,13 @@ export function LLMPromptsScene(): JSX.Element {<LemonInputdata-attr="llma-prompt-duplicate-name"placeholder="my-prompt-copy"+ maxLength={PROMPT_NAME_MAX_LENGTH}autoFocus/></LemonField>),errors: {- newName: (name: string) =>- !name- ? 'You must enter a name'- : !/^[a-zA-Z0-9_-]+$/.test(name)- ? 'Only letters, numbers, hyphens, and underscores allowed'- : undefined,+ newName: (name: string) => validatePromptName(name),},onSubmit: async ({ newName }) => {duplicatePrompt(prompt.name, newName)diff --git a/products/ai_observability/frontend/prompts/llmPromptLogic.ts b/products/ai_observability/frontend/prompts/llmPromptLogic.tsindex a9cab8730ea5..46cc63365ebc 100644--- a/products/ai_observability/frontend/prompts/llmPromptLogic.ts+++ b/products/ai_observability/frontend/prompts/llmPromptLogic.ts@@ -44,6 +44,7 @@ import {import type { llmPromptLogicType } from './llmPromptLogicType'import { llmPromptsLogic } from './llmPromptsLogic'import { LLM_PROMPTS_FORCE_RELOAD_PARAM } from './llmPromptsLogic'+import { getApiErrorDetail, validatePromptName } from './utils'export enum PromptMode {View = 'view',@@ -82,7 +83,6 @@ const DEFAULT_PROMPT_FORM_VALUES: PromptFormValues = {const PROMPT_FETCHED_EVENT = '$llm_prompt_fetched'const PROMPT_VERSIONS_LIMIT = 50-export const PROMPT_NAME_MAX_LENGTH = 255const DEFAULT_PROMPT_ANALYTICS_DATE_FROM = '-1d'const STALE_PROMPT_ERROR_MESSAGE ='This prompt changed while you were editing it. Your edits are preserved — review the latest version and publish again.'@@ -131,13 +131,6 @@ function buildPromptVersionSummary(prompt: LLMPrompt, isLatest: boolean): LLMPro}}-export function getApiErrorDetail(error: unknown): string | undefined {- if (error !== null && typeof error === 'object' && 'detail' in error && typeof error.detail === 'string') {- return error.detail- }- return undefined-}-function isNameFieldValidationError(error: unknown): error is { attr: 'name'; detail: string } {return (error !== null &&@@ -265,15 +258,7 @@ export const llmPromptLogic = kea<llmPromptLogicType>([options: { showErrorsOnTouch: true },errors: ({ name, prompt }) => ({- name: !name?.trim()- ? 'Name is required'- : name.toLowerCase() === 'new'- ? "'new' is a reserved name and cannot be used"- : name.length > PROMPT_NAME_MAX_LENGTH- ? `Name must be ${PROMPT_NAME_MAX_LENGTH} characters or fewer`- : !/^[a-zA-Z0-9_-]+$/.test(name)- ? 'Only letters, numbers, hyphens (-), and underscores (_) are allowed'- : undefined,+ name: validatePromptName(name),prompt: !prompt?.trim() ? 'Prompt content is required' : undefined,}),@@ -686,8 +671,8 @@ export const llmPromptLogic = kea<llmPromptLogicType>([...router.values.searchParams,[LLM_PROMPTS_FORCE_RELOAD_PARAM]: String(Date.now()),})- } catch {- lemonToast.error('Failed to archive prompt')+ } catch (error) {+ lemonToast.error(getApiErrorDetail(error) || 'Failed to archive prompt')}}},diff --git a/products/ai_observability/frontend/prompts/llmPromptsLogic.ts b/products/ai_observability/frontend/prompts/llmPromptsLogic.tsindex c49960137f22..cd0cc6b3cd2a 100644--- a/products/ai_observability/frontend/prompts/llmPromptsLogic.ts+++ b/products/ai_observability/frontend/prompts/llmPromptsLogic.ts@@ -15,6 +15,7 @@ import { LLMPrompt } from '~/types'import { cleanPagedSearchOrderParams } from '../utils'import type { llmPromptsLogicType } from './llmPromptsLogicType'+import { getApiErrorDetail } from './utils'export const PROMPTS_PER_PAGE = 30export const LLM_PROMPTS_FORCE_RELOAD_PARAM = 'llm_prompts_force_reload'@@ -157,8 +158,8 @@ export const llmPromptsLogic = kea<llmPromptsLogicType>([await api.llmPrompts.archiveByName(promptName)lemonToast.info(`${promptName || 'Prompt'} has been archived.`)await asyncActions.loadPrompts(false)- } catch {- lemonToast.error('Failed to archive prompt')+ } catch (error) {+ lemonToast.error(getApiErrorDetail(error) || 'Failed to archive prompt')}},@@ -167,8 +168,8 @@ export const llmPromptsLogic = kea<llmPromptsLogicType>([await api.llmPrompts.duplicateByName(promptName, newName)lemonToast.success(`Prompt duplicated as "${newName}".`)router.actions.push(urls.aiObservabilityPrompt(newName))- } catch {- lemonToast.error('Failed to duplicate prompt')+ } catch (error) {+ lemonToast.error(getApiErrorDetail(error) || 'Failed to duplicate prompt')}},})),diff --git a/products/ai_observability/frontend/prompts/promptSceneComponents.tsx b/products/ai_observability/frontend/prompts/promptSceneComponents.tsxindex aa33a0079a24..16a25c04e270 100644--- a/products/ai_observability/frontend/prompts/promptSceneComponents.tsx+++ b/products/ai_observability/frontend/prompts/promptSceneComponents.tsx@@ -24,8 +24,9 @@ import { useTracesQueryContext } from '../AIObservabilityTracesScene'import { MarkdownOutline } from '../components/MarkdownOutline'import { CreatePromptExperimentModal } from './CreatePromptExperimentModal'import { createPromptExperimentModalLogic } from './createPromptExperimentModalLogic'-import { PROMPT_NAME_MAX_LENGTH, PromptAnalyticsScope, isPrompt, llmPromptLogic } from './llmPromptLogic'+import { PromptAnalyticsScope, isPrompt, llmPromptLogic } from './llmPromptLogic'import { promptExperimentsLogic } from './promptExperimentsLogic'+import { PROMPT_NAME_MAX_LENGTH } from './utils'const MonacoDiffEditor = lazy(() => import('lib/components/MonacoDiffEditor'))diff --git a/products/ai_observability/frontend/prompts/utils.ts b/products/ai_observability/frontend/prompts/utils.tsindex 552d580bb923..2b64ce03fc8b 100644--- a/products/ai_observability/frontend/prompts/utils.ts+++ b/products/ai_observability/frontend/prompts/utils.ts@@ -1,5 +1,30 @@import { LemonDialog } from 'lib/lemon-ui/LemonDialog'+export const PROMPT_NAME_MAX_LENGTH = 255++export function validatePromptName(name: string | undefined): string | undefined {+ if (!name?.trim()) {+ return 'Name is required'+ }+ if (name.toLowerCase() === 'new') {+ return "'new' is a reserved name and cannot be used"+ }+ if (name.length > PROMPT_NAME_MAX_LENGTH) {+ return `Name must be ${PROMPT_NAME_MAX_LENGTH} characters or fewer`+ }+ if (!/^[a-zA-Z0-9_-]+$/.test(name)) {+ return 'Only letters, numbers, hyphens (-), and underscores (_) are allowed'+ }+ return undefined+}++export function getApiErrorDetail(error: unknown): string | undefined {+ if (error !== null && typeof error === 'object' && 'detail' in error && typeof error.detail === 'string') {+ return error.detail+ }+ return undefined+}+export function openArchivePromptDialog(onArchive: () => void): void {LemonDialog.open({title: 'Archive prompt?',