: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): warn about unfilled playground variables (#109798)
Juraj Majerik2fb6a20e7d5c
diff --git a/products/ai_observability/frontend/playground/PlaygroundVariablesPanel.tsx b/products/ai_observability/frontend/playground/PlaygroundVariablesPanel.tsxindex 1953a1f122db..2422ed052acc 100644--- a/products/ai_observability/frontend/playground/PlaygroundVariablesPanel.tsx+++ b/products/ai_observability/frontend/playground/PlaygroundVariablesPanel.tsx@@ -1,7 +1,7 @@import { useActions, useValues } from 'kea'-import { IconChevronRight } from '@posthog/icons'-import { LemonButton, LemonTextArea } from '@posthog/lemon-ui'+import { IconChevronRight, IconWarning } from '@posthog/icons'+import { LemonButton, LemonTag, LemonTextArea, Tooltip } from '@posthog/lemon-ui'import { AnimatedCollapsible } from 'lib/components/AnimatedCollapsible'@@ -10,7 +10,7 @@ import { llmPlaygroundVariablesLogic } from './llmPlaygroundVariablesLogic'import { getVariableValue } from './playgroundTemplating'export function PlaygroundVariablesPanel(): JSX.Element {- const { detectedVariables, variableValues } = useValues(llmPlaygroundVariablesLogic)+ const { detectedVariables, unfilledVariables, variableValues } = useValues(llmPlaygroundVariablesLogic)const { setVariableValue } = useActions(llmPlaygroundVariablesLogic)const { collapsedSections } = useValues(llmPlaygroundPromptsLogic)const { toggleCollapsed } = useActions(llmPlaygroundPromptsLogic)@@ -19,7 +19,7 @@ export function PlaygroundVariablesPanel(): JSX.Element {return (<div className="border rounded p-4 py-2 shrink-0">- <div className={collapsed ? '' : 'mb-2'}>+ <div className={`flex items-center gap-2 ${collapsed ? '' : 'mb-2'}`}><LemonButtonsize="small"noPadding@@ -32,6 +32,11 @@ export function PlaygroundVariablesPanel(): JSX.Element {>Variables{detectedVariables.length > 0 ? ` (${detectedVariables.length})` : ''}</LemonButton>+ {unfilledVariables.length > 0 && (+ <LemonTag type="warning" size="small">+ {unfilledVariables.length} unfilled+ </LemonTag>+ )}</div><AnimatedCollapsible collapsed={collapsed}>@@ -45,6 +50,18 @@ export function PlaygroundVariablesPanel(): JSX.Element {{detectedVariables.map((name) => (<div key={name} className="flex items-start gap-2"><code className="text-xs pt-2 whitespace-nowrap">{`{{${name}}}`}</code>+ {unfilledVariables.includes(name) && (+ <Tooltip title="No value set. The placeholder is sent as written.">+ <span+ tabIndex={0}+ role="img"+ aria-label="No value set"+ className="text-warning mt-2 shrink-0"+ >+ <IconWarning />+ </span>+ </Tooltip>+ )}<LemonTextAreaclassName="text-sm flex-1"placeholder="Value"diff --git a/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.test.ts b/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.test.tsindex c418361c2d30..d34561f65bb7 100644--- a/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.test.ts+++ b/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.test.ts@@ -9,7 +9,7 @@ import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'import { AccessControlLevel } from '~/types'-import { llmPlaygroundPromptsLogic } from './llmPlaygroundPromptsLogic'+import { createPromptConfig, llmPlaygroundPromptsLogic } from './llmPlaygroundPromptsLogic'import {appendToolCallChunk,describeError,@@ -140,6 +140,55 @@ describe('llmPlaygroundRunLogic', () => {streamSpy.mockRestore()})+ it('warns about unfilled variables on run and stays quiet once they are filled', async () => {+ // Without the warning, a run with a literal {{placeholder}} in it gives no signal;+ // a warning that names a skipped panel's variable, or keeps firing after the+ // values are filled, misreports what was sent.+ const streamSpy = jest.spyOn(api, 'stream').mockImplementation(async () => {})+ const toastSpy = jest.spyOn(lemonToast, 'warning').mockImplementation(() => 'toast-id')+ const captureSpy = jest.spyOn(posthog, 'capture')++ const logic = llmPlaygroundRunLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ // The second panel has no messages, so it is skipped: {{ghost}} is never sent+ llmPlaygroundPromptsLogic.actions.setPromptConfigs([+ createPromptConfig({+ model: 'gpt-5-mini',+ messages: [{ role: 'user', content: '{{topic}} in a {{tone}} tone' }],+ }),+ createPromptConfig({ model: 'gpt-5-mini', systemPrompt: 'About {{ghost}}', messages: [] }),+ ])+ llmPlaygroundRunLogic.actions.submitPrompt()+ await expectLogic(logic).toFinishAllListeners()++ expect(toastSpy).toHaveBeenCalledWith('No value for {{topic}}, {{tone}}. The placeholders are sent as written.')+ expect(captureSpy).toHaveBeenCalledWith(+ 'llma playground prompt submitted',+ expect.objectContaining({ variable_count: 2, unfilled_variable_count: 2 })+ )++ toastSpy.mockClear()+ llmPlaygroundVariablesLogic.actions.setVariableValue('topic', 'penguins')+ llmPlaygroundRunLogic.actions.submitPrompt()+ await expectLogic(logic).toFinishAllListeners()++ expect(toastSpy).toHaveBeenCalledWith('No value for {{tone}}. The placeholder is sent as written.')++ toastSpy.mockClear()+ llmPlaygroundVariablesLogic.actions.setVariableValue('tone', 'formal')+ llmPlaygroundRunLogic.actions.submitPrompt()+ await expectLogic(logic).toFinishAllListeners()++ expect(toastSpy).not.toHaveBeenCalled()++ logic.unmount()+ streamSpy.mockRestore()+ toastSpy.mockRestore()+ captureSpy.mockRestore()+ })+it('does not run a completion without editor access to the playground and explains why', async () => {// Both message textareas submit on Cmd+Enter, bypassing the Run button's disabledReason,// so the gate has to hold in the logic itself.diff --git a/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.ts b/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.tsindex 19f1aa1fd755..f8e26b1c414f 100644--- a/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.ts+++ b/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.ts@@ -17,7 +17,7 @@ import { llmPlaygroundModelLogic } from './llmPlaygroundModelLogic'import { llmPlaygroundPromptsLogic, type Message, type PromptConfig } from './llmPlaygroundPromptsLogic'import { llmPlaygroundVariablesLogic } from './llmPlaygroundVariablesLogic'import { resolveProviderKeyForPrompt } from './playgroundModelMatching'-import { substituteVariables } from './playgroundTemplating'+import { extractVariablesFromTexts, getVariableValue, substituteVariables } from './playgroundTemplating'interface ToolCallChunk {id?: string@@ -331,6 +331,16 @@ export const llmPlaygroundRunLogic = kea<llmPlaygroundRunLogicType>([return}+ // Count only the prompts actually submitted; a skipped panel's variables are not sent,+ // so they belong in neither the warning nor the event.+ const runVariables = extractVariablesFromTexts(+ runnablePrompts.flatMap(({ prompt, messagesToSend }) => [+ prompt.systemPrompt,+ ...messagesToSend.map((m) => m.content),+ ])+ )+ const runUnfilledVariables = runVariables.filter((name) => !getVariableValue(values.variableValues, name))+posthog.capture('llma playground prompt submitted', {prompt_count: runnablePrompts.length,models: runnablePrompts.map(({ prompt }) => prompt.model),@@ -339,8 +349,19 @@ export const llmPlaygroundRunLogic = kea<llmPlaygroundRunLogicType>([(sum, { messagesToSend }) => sum + messagesToSend.length,0),+ variable_count: runVariables.length,+ unfilled_variable_count: runUnfilledVariables.length,})+ if (runUnfilledVariables.length > 0) {+ const names = runUnfilledVariables.map((name) => `{{${name}}}`).join(', ')+ const suffix =+ runUnfilledVariables.length === 1+ ? 'The placeholder is sent as written.'+ : 'The placeholders are sent as written.'+ lemonToast.warning(`No value for ${names}. ${suffix}`)+ }+const abortController = new AbortController()currentAbortController = abortControllertry {diff --git a/products/ai_observability/frontend/playground/llmPlaygroundVariablesLogic.ts b/products/ai_observability/frontend/playground/llmPlaygroundVariablesLogic.tsindex 68f88a655bb5..b760b931573a 100644--- a/products/ai_observability/frontend/playground/llmPlaygroundVariablesLogic.ts+++ b/products/ai_observability/frontend/playground/llmPlaygroundVariablesLogic.ts@@ -1,7 +1,7 @@import { MakeLogicType, actions, connect, kea, path, props, reducers, selectors } from 'kea'import { llmPlaygroundPromptsLogic, type PromptConfig } from './llmPlaygroundPromptsLogic'-import { extractVariables, getVariableValue } from './playgroundTemplating'+import { extractVariablesFromTexts, getVariableValue } from './playgroundTemplating'export type LLMPlaygroundVariablesLogicProps = Record<string, never>@@ -82,19 +82,10 @@ export const llmPlaygroundVariablesLogic = kea<llmPlaygroundVariablesLogicType>(selectors({detectedVariables: [(s) => [s.promptConfigs],- (promptConfigs: PromptConfig[]): string[] => {- const names: string[] = []- for (const prompt of promptConfigs) {- for (const text of [prompt.systemPrompt, ...prompt.messages.map((m) => m.content)]) {- for (const name of extractVariables(text)) {- if (!names.includes(name)) {- names.push(name)- }- }- }- }- return names- },+ (promptConfigs: PromptConfig[]): string[] =>+ extractVariablesFromTexts(+ promptConfigs.flatMap((prompt) => [prompt.systemPrompt, ...prompt.messages.map((m) => m.content)])+ ),],unfilledVariables: [(s) => [s.detectedVariables, s.variableValues],diff --git a/products/ai_observability/frontend/playground/playgroundTemplating.ts b/products/ai_observability/frontend/playground/playgroundTemplating.tsindex 663daa3fc95d..7d90f95fc005 100644--- a/products/ai_observability/frontend/playground/playgroundTemplating.ts+++ b/products/ai_observability/frontend/playground/playgroundTemplating.ts@@ -19,6 +19,19 @@ export function extractVariables(text: string): string[] {return names}+/** Distinct variable names across several texts, in order of first appearance. */+export function extractVariablesFromTexts(texts: string[]): string[] {+ const names: string[] = []+ for (const text of texts) {+ for (const name of extractVariables(text)) {+ if (!names.includes(name)) {+ names.push(name)+ }+ }+ }+ return names+}+/*** Own-property read of a variable value. A plain record inherits `constructor`,* `toString` and the rest of Object.prototype, so a bare `values[name]` would