: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(aio): render evaluation templates as a compact list (#72385)
Radu Raicea4450ce1bf40e
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex 16a95824e285..4105caf0094b 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -344,6 +344,7 @@ export const FEATURE_FLAGS = {LLM_ANALYTICS_DATASETS: 'llm-analytics-datasets', // owner: #team-ai-observability #team-posthog-aiLLM_ANALYTICS_EARLY_ADOPTERS: 'llm-analytics-early-adopters', // owner: #team-ai-observabilityLLM_ANALYTICS_EVALUATIONS_REPORTS: 'llm-analytics-evaluations-reports', // owner: #team-ai-observability+ LLM_ANALYTICS_EVALUATIONS_START_WITH_AI: 'llm-analytics-evaluations-start-with-ai', // owner: #team-ai-observabilityLLM_ANALYTICS_OFFLINE_EVALS: 'llm-analytics-offline-evals', // owner: #team-ai-observabilityLLM_ANALYTICS_TAGS: 'llm-analytics-tags', // owner: #team-ai-observabilityLLM_ANALYTICS_TRACE_NAVIGATION: 'llm-analytics-trace-navigation', // owner: #team-ai-observabilitydiff --git a/products/ai_observability/frontend/AIObservabilityTraceScene.tsx b/products/ai_observability/frontend/AIObservabilityTraceScene.tsxindex bcb38c1c6d06..ee51a898c8e5 100644--- a/products/ai_observability/frontend/AIObservabilityTraceScene.tsx+++ b/products/ai_observability/frontend/AIObservabilityTraceScene.tsx@@ -633,6 +633,7 @@ function CreateSentimentEvaluationButton({ traceId }: { traceId: string }): JSX.const createSentimentEvaluationUrl = combineUrl(urls.aiObservabilityEvaluation('new'), {type: 'sentiment',+ returnTo: urls.aiObservabilityTrace(traceId),}).urlreturn (diff --git a/products/ai_observability/frontend/evaluations/AIObservabilityEvaluation.tsx b/products/ai_observability/frontend/evaluations/AIObservabilityEvaluation.tsxindex 1708a0022f57..e7e34b3e824c 100644--- a/products/ai_observability/frontend/evaluations/AIObservabilityEvaluation.tsx+++ b/products/ai_observability/frontend/evaluations/AIObservabilityEvaluation.tsx@@ -56,6 +56,7 @@ import { EvaluationTarget, EvaluationType } from './types'export function AIObservabilityEvaluation(): JSX.Element {const {evaluation,+ evaluationBackTarget,evaluationLoading,evaluationFormSubmitting,hasUnsavedChanges,@@ -225,7 +226,7 @@ export function AIObservabilityEvaluation(): JSX.Element {if (hasUnsavedChanges) {resetEvaluation()}- push(combineUrl(urls.aiObservabilityEvaluations(), searchParams).url)+ push(evaluationBackTarget.path)}const hogEvaluationMethodOptions: { value: EvaluationType; label: string }[] = [diff --git a/products/ai_observability/frontend/evaluations/AIObservabilityEvaluationsScene.tsx b/products/ai_observability/frontend/evaluations/AIObservabilityEvaluationsScene.tsxindex 0c414acac5e8..716714615f6c 100644--- a/products/ai_observability/frontend/evaluations/AIObservabilityEvaluationsScene.tsx+++ b/products/ai_observability/frontend/evaluations/AIObservabilityEvaluationsScene.tsx@@ -428,15 +428,12 @@ function AIObservabilityEvaluationsContent(): JSX.Element {</LemonBanner>)}- <LemonBanner type="info" dismissKey="evals-billing-notice">- Each evaluation run counts as an AI observability event.- </LemonBanner>-<div className="flex justify-between items-center"><div><h2 className="text-xl font-semibold">Online evals</h2><p className="text-muted">- Configure evaluation prompts and triggers to automatically assess your AI generations.+ Configure evaluation prompts and triggers to automatically assess your AI generations. Each+ evaluation run is billed as an AI observability event.</p></div><AccessControlActiondiff --git a/products/ai_observability/frontend/evaluations/EvaluationTemplates.tsx b/products/ai_observability/frontend/evaluations/EvaluationTemplates.tsxindex 22e05c26de9b..39f3120d7f06 100644--- a/products/ai_observability/frontend/evaluations/EvaluationTemplates.tsx+++ b/products/ai_observability/frontend/evaluations/EvaluationTemplates.tsx@@ -1,15 +1,31 @@import { useValues } from 'kea'-import { combineUrl, router } from 'kea-router'+import { router } from 'kea-router'import posthog from 'posthog-js'import * as judgePng from '@posthog/brand/hoggies/png/judge'-import { IconArrowLeft, IconCode, IconEye, IconPlus, IconTarget, IconThumbsUp, IconWarning } from '@posthog/icons'-import { LemonButton, LemonTag, Link } from '@posthog/lemon-ui'+import {+ IconArrowLeft,+ IconCode,+ IconEmoji,+ IconEye,+ IconPlus,+ IconSearch,+ IconSparkles,+ IconTarget,+ IconThumbsUp,+ IconWarning,+ IconWrench,+} from '@posthog/icons'+import { LemonButton, LemonTag, LemonTagType, Link } from '@posthog/lemon-ui'import { pngHoggie } from 'lib/brand/hoggies'+import { FEATURE_FLAGS } from 'lib/constants'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { SceneExport } from 'scenes/sceneTypes'-import { urls } from 'scenes/urls'+import { useOpenAi } from '~/scenes/max/useOpenAi'++import { getEvaluationBackTarget, getEvaluationTemplateSelectionUrl } from './evaluationNavigation'import { EvaluationTemplate, defaultEvaluationTemplates } from './templates'const HedgehogJudge = pngHoggie(judgePng)@@ -18,7 +34,7 @@ export const scene: SceneExport = {component: EvaluationTemplatesScene,}-interface TemplateCardProps {+interface TemplateRowProps {template: EvaluationTemplate | 'blank'}@@ -35,6 +51,12 @@ function getTemplateIcon(icon: EvaluationTemplate['icon']): JSX.Element {return <IconWarning className={iconClass} />case 'code':return <IconCode className={iconClass} />+ case 'search':+ return <IconSearch className={iconClass} />+ case 'wrench':+ return <IconWrench className={iconClass} />+ case 'emoji':+ return <IconEmoji className={iconClass} />default: {const exhaustiveCheck: never = iconreturn exhaustiveCheck@@ -42,8 +64,64 @@ function getTemplateIcon(icon: EvaluationTemplate['icon']): JSX.Element {}}-function TemplateCard({ template }: TemplateCardProps): JSX.Element {+function getTemplateTypeTag(evaluationType: EvaluationTemplate['evaluation_type']): {+ label: string+ type: LemonTagType+} {+ switch (evaluationType) {+ case 'hog':+ return { label: 'Hog', type: 'option' }+ case 'sentiment':+ return { label: 'Sentiment', type: 'success' }+ case 'llm_judge':+ return { label: 'LLM judge', type: 'caution' }+ default: {+ const exhaustiveCheck: never = evaluationType+ return exhaustiveCheck+ }+ }+}++interface PickerRowProps {+ dataAttr: string+ description: string+ icon: JSX.Element+ onClick: () => void+ tag?: {+ label: string+ type: LemonTagType+ }+ title: string+}++function PickerRow({ dataAttr, description, icon, onClick, tag, title }: PickerRowProps): JSX.Element {+ return (+ <button+ className="flex items-center gap-4 w-full text-left px-4 py-3 hover:bg-fill-highlight-50 focus:bg-fill-highlight-50 focus:outline-none transition-colors cursor-pointer"+ data-attr={dataAttr}+ onClick={onClick}+ >+ <div className="bg-primary-3000/10 rounded-lg flex-shrink-0 size-10 flex items-center justify-center">+ {icon}+ </div>+ <div className="flex-1 min-w-0">+ <div className="flex items-center gap-2">+ <h3 className="text-base font-semibold text-default mb-0">{title}</h3>+ {tag && (+ <LemonTag type={tag.type} size="small">+ {tag.label}+ </LemonTag>+ )}+ </div>+ <p className="text-sm text-secondary mb-0">{description}</p>+ </div>+ </button>+ )+}++function TemplateRow({ template }: TemplateRowProps): JSX.Element {const isBlank = template === 'blank'+ const typeTag = isBlank ? null : getTemplateTypeTag(template.evaluation_type)const { searchParams } = useValues(router)const handleClick = (): void => {@@ -51,50 +129,44 @@ function TemplateCard({ template }: TemplateCardProps): JSX.Element {template_key: isBlank ? 'blank' : template.key,})- if (isBlank) {- router.actions.push(combineUrl(urls.aiObservabilityEvaluation('new'), searchParams).url)- } else {- const url = combineUrl(urls.aiObservabilityEvaluation('new'), {- ...searchParams,- template: template.key,- }).url- router.actions.push(url)- }+ router.actions.push(getEvaluationTemplateSelectionUrl(searchParams, isBlank ? undefined : template.key))}return (- <button- className="relative flex flex-col bg-bg-light border border-border rounded-lg hover:border-primary-3000-hover focus:border-primary-3000-hover focus:outline-none transition-colors text-left group p-6 cursor-pointer min-h-[180px]"- data-attr={isBlank ? 'blank-evaluation-template' : `evaluation-template-${template.key}`}+ <PickerRow+ dataAttr={isBlank ? 'blank-evaluation-template' : `evaluation-template-${template.key}`}+ description={isBlank ? 'Build a custom evaluation with your own configuration' : template.description}+ icon={isBlank ? <IconPlus className="w-5 h-5 text-primary-3000" /> : getTemplateIcon(template.icon)}onClick={handleClick}- >- <div className="flex flex-col items-center text-center gap-4 h-full">- <div className="bg-primary-3000/10 rounded-lg flex-shrink-0 size-12 flex items-center justify-center">- {isBlank ? <IconPlus className="w-6 h-6 text-primary-3000" /> : getTemplateIcon(template.icon)}- </div>- <div className="flex-1 flex flex-col justify-start">- <div className="flex items-center justify-center gap-2 mb-2">- <h3 className="text-base font-semibold text-default mb-0">- {isBlank ? 'Create from scratch' : template.name}- </h3>- {!isBlank && (- <LemonTag type={template.evaluation_type === 'hog' ? 'option' : 'caution'} size="small">- {template.evaluation_type === 'hog' ? 'Hog' : 'LLM judge'}- </LemonTag>- )}- </div>- <p className="text-sm text-secondary leading-relaxed">- {isBlank- ? 'Build a custom evaluation with your own prompt and configuration'- : template.description}- </p>- </div>- </div>- </button>+ tag={typeTag ?? undefined}+ title={isBlank ? 'Create from scratch' : template.name}+ />+ )+}++function StartWithAiRow(): JSX.Element {+ const { openAi } = useOpenAi()++ const handleClick = (): void => {+ posthog.capture('llm evaluation template selected', { template_key: 'start_with_ai' })+ openAi(+ 'Create an online evaluation for me. First explore my recent AI traces to find failure modes worth evaluating, then set one up to catch the most important one.'+ )+ }++ return (+ <PickerRow+ dataAttr="start-with-ai-evaluation-template"+ description="Let PostHog AI explore your traces and build an evaluation for you"+ icon={<IconSparkles className="w-5 h-5 text-primary-3000" />}+ onClick={handleClick}+ tag={{ label: 'Beta', type: 'completion' }}+ title="Start with AI"+ />)}-interface TemplateGridProps {+interface TemplatePickerProps {title: stringdescription: stringshowBackButton?: boolean@@ -102,14 +174,16 @@ interface TemplateGridProps {minHeight?: '60vh' | '80vh'}-function TemplateGrid({+function TemplatePicker({title,description,showBackButton = false,learnMoreUrl,minHeight = '60vh',-}: TemplateGridProps): JSX.Element {+}: TemplatePickerProps): JSX.Element {const { searchParams } = useValues(router)+ const { featureFlags } = useValues(featureFlagLogic)+ const showStartWithAi = !!featureFlags[FEATURE_FLAGS.LLM_ANALYTICS_EVALUATIONS_START_WITH_AI]return (<div className="flex flex-col items-center justify-center py-8" style={{ minHeight }}>@@ -119,9 +193,7 @@ function TemplateGrid({<LemonButtontype="secondary"icon={<IconArrowLeft />}- onClick={() =>- router.actions.push(combineUrl(urls.aiObservabilityEvaluations(), searchParams).url)- }+ onClick={() => router.actions.push(getEvaluationBackTarget(false, searchParams).path)}size="small">Back to Evaluations@@ -147,10 +219,11 @@ function TemplateGrid({</p></div>- <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">- <TemplateCard template="blank" />+ <div className="flex flex-col border border-border rounded-lg divide-y divide-border overflow-hidden bg-bg-light">+ {showStartWithAi && <StartWithAiRow />}+ <TemplateRow template="blank" />{defaultEvaluationTemplates.map((template) => (- <TemplateCard key={template.key} template={template} />+ <TemplateRow key={template.key} template={template} />))}</div></div>@@ -161,7 +234,7 @@ function TemplateGrid({export function EvaluationTemplatesScene(): JSX.Element {return (- <TemplateGrid+ <TemplatePickertitle="Choose an evaluation template"description="Select a pre-configured template to get started quickly, or create your own from scratch"showBackButton@@ -172,7 +245,7 @@ export function EvaluationTemplatesScene(): JSX.Element {export function EvaluationTemplatesEmptyState(): JSX.Element {return (- <TemplateGrid+ <TemplatePickertitle="Create your first evaluation"description="Select a pre-configured template to get started quickly, or create your own from scratch."showBackButton={false}diff --git a/products/ai_observability/frontend/evaluations/evaluationNavigation.test.ts b/products/ai_observability/frontend/evaluations/evaluationNavigation.test.tsnew file mode 100644index 000000000000..8f3c0359b99d--- /dev/null+++ b/products/ai_observability/frontend/evaluations/evaluationNavigation.test.ts@@ -0,0 +1,63 @@+import { urls } from 'scenes/urls'++import { getEvaluationBackTarget, getEvaluationTemplateSelectionUrl } from './evaluationNavigation'++describe('evaluation navigation', () => {+ it.each([+ ['blank', undefined, {}],+ ['Hog', 'cost_latency', { template: 'cost_latency' }],+ ])('builds a clean %s template selection URL', (_name, templateKey, expectedTemplateParams) => {+ const url = new URL(+ getEvaluationTemplateSelectionUrl(+ {+ tab: 'settings',+ template: 'sentiment',+ type: 'sentiment',+ returnTo: urls.aiObservabilitySentiment(),+ },+ templateKey+ ),+ 'https://posthog.test'+ )++ expect(url.pathname).toBe(urls.aiObservabilityEvaluation('new'))+ expect(Object.fromEntries(url.searchParams)).toEqual({+ tab: 'settings',+ ...expectedTemplateParams,+ returnTo: urls.aiObservabilityEvaluationTemplates(),+ })+ })++ it.each([+ [+ 'template picker',+ true,+ { template: 'cost_latency', type: 'sentiment', tab: 'settings' },+ 'Templates',+ `${urls.aiObservabilityEvaluationTemplates()}?tab=settings`,+ ],+ [+ 'sentiment tab',+ true,+ { type: 'sentiment', returnTo: urls.aiObservabilitySentiment() },+ 'Sentiment',+ urls.aiObservabilitySentiment(),+ ],+ [+ 'trace',+ true,+ { type: 'sentiment', returnTo: urls.aiObservabilityTrace('trace-id') },+ 'Trace',+ urls.aiObservabilityTrace('trace-id'),+ ],+ [+ 'evaluation list',+ false,+ { template: 'sentiment', type: 'sentiment', tab: 'settings' },+ 'Evaluations',+ `${urls.aiObservabilityEvaluations()}?tab=settings`,+ ],+ ])('returns a draft opened from the %s to its origin', (_origin, isNew, searchParams, name, path) => {+ expect(getEvaluationBackTarget(isNew, searchParams)).toMatchObject({ name, path })+ })+})diff --git a/products/ai_observability/frontend/evaluations/evaluationNavigation.ts b/products/ai_observability/frontend/evaluations/evaluationNavigation.tsnew file mode 100644index 000000000000..a1aee4521847--- /dev/null+++ b/products/ai_observability/frontend/evaluations/evaluationNavigation.ts@@ -0,0 +1,87 @@+import { combineUrl } from 'kea-router'++import { urls } from 'scenes/urls'++export interface EvaluationBackTarget {+ name: 'Evaluations' | 'Templates' | 'Sentiment' | 'Trace'+ path: string+ key: string+ iconType: 'llm_evaluations' | 'llm_analytics'+}++function searchParamsWithoutEvaluationSource(searchParams: Record<string, any>): Record<string, any> {+ const { returnTo: _returnTo, template: _template, type: _type, ...remainingSearchParams } = searchParams+ return remainingSearchParams+}++function targetFromReturnTo(returnTo: unknown): EvaluationBackTarget | null {+ if (returnTo === urls.aiObservabilityEvaluationTemplates()) {+ return {+ name: 'Templates',+ path: returnTo,+ key: 'AIObservabilityEvaluationTemplates',+ iconType: 'llm_evaluations',+ }+ }++ if (returnTo === urls.aiObservabilitySentiment()) {+ return {+ name: 'Sentiment',+ path: returnTo,+ key: 'AIObservabilitySentiment',+ iconType: 'llm_analytics',+ }+ }++ if (typeof returnTo === 'string' && returnTo.startsWith(`${urls.aiObservabilityTraces()}/`)) {+ return {+ name: 'Trace',+ path: returnTo,+ key: 'AIObservabilityTrace',+ iconType: 'llm_analytics',+ }+ }++ return null+}++export function getEvaluationBackTarget(+ isNewEvaluation: boolean,+ searchParams: Record<string, any>+): EvaluationBackTarget {+ const remainingSearchParams = searchParamsWithoutEvaluationSource(searchParams)+ const evaluationsTarget: EvaluationBackTarget = {+ name: 'Evaluations',+ path: combineUrl(urls.aiObservabilityEvaluations(), remainingSearchParams).url,+ key: 'AIObservabilityEvaluations',+ iconType: 'llm_evaluations',+ }++ if (!isNewEvaluation) {+ return evaluationsTarget+ }++ const returnToTarget = targetFromReturnTo(searchParams.returnTo)+ if (returnToTarget) {+ return returnToTarget+ }++ if (typeof searchParams.template === 'string') {+ return {+ name: 'Templates',+ path: combineUrl(urls.aiObservabilityEvaluationTemplates(), remainingSearchParams).url,+ key: 'AIObservabilityEvaluationTemplates',+ iconType: 'llm_evaluations',+ }+ }++ return evaluationsTarget+}++export function getEvaluationTemplateSelectionUrl(searchParams: Record<string, any>, templateKey?: string): string {+ return combineUrl(urls.aiObservabilityEvaluation('new'), {+ ...searchParamsWithoutEvaluationSource(searchParams),+ ...(templateKey ? { template: templateKey } : {}),+ returnTo: urls.aiObservabilityEvaluationTemplates(),+ }).url+}diff --git a/products/ai_observability/frontend/evaluations/llmEvaluationLogic.test.ts b/products/ai_observability/frontend/evaluations/llmEvaluationLogic.test.tsindex e291ca2b7c57..444deb93735c 100644--- a/products/ai_observability/frontend/evaluations/llmEvaluationLogic.test.ts+++ b/products/ai_observability/frontend/evaluations/llmEvaluationLogic.test.ts@@ -580,6 +580,19 @@ return result`,})})+ describe('breadcrumbs', () => {+ it('does not show the template picker while an existing evaluation loads', () => {+ logic = llmEvaluationLogic({ evaluationId: 'eval-123' })+ logic.mount()++ expect(logic.values.evaluation).toBeNull()+ expect(logic.values.breadcrumbs.map((breadcrumb) => breadcrumb.name)).toEqual([+ 'Evaluations',+ 'New Evaluation',+ ])+ })+ })+describe('runsSummary', () => {beforeEach(() => {logic = llmEvaluationLogic({ evaluationId: 'eval-123' })@@ -693,19 +706,45 @@ return result`,})})- it('applies template when provided', async () => {- logic = llmEvaluationLogic({ evaluationId: 'new', templateKey: 'factuality' })+ it.each([+ {+ name: 'LLM judge',+ templateKey: 'relevance',+ expectedEvaluation: {+ name: 'Relevance',+ evaluation_type: 'llm_judge',+ evaluation_config: { prompt: expect.stringContaining('relevant') },+ output_type: 'boolean',+ },+ },+ {+ name: 'Hog',+ templateKey: 'cost_latency',+ expectedEvaluation: {+ name: 'Cost & latency',+ evaluation_type: 'hog',+ evaluation_config: { source: expect.stringContaining('latency'), bytecode: [] },+ output_type: 'boolean',+ },+ },+ {+ name: 'sentiment',+ templateKey: 'sentiment',+ expectedEvaluation: {+ name: 'Sentiment analysis',+ evaluation_type: 'sentiment',+ evaluation_config: { source: 'user_messages' },+ output_type: 'sentiment',+ },+ },+ ])('applies the $name template', async ({ templateKey, expectedEvaluation }) => {+ logic = llmEvaluationLogic({ evaluationId: 'new', templateKey })logic.mount()await expectLogic(logic).toDispatchActions(['loadEvaluationSuccess'])await expectLogic(logic).toMatchValues({- evaluation: expect.objectContaining({- name: expect.any(String),- evaluation_config: expect.objectContaining({- prompt: expect.any(String),- }),- }),+ evaluation: expect.objectContaining(expectedEvaluation),})})})diff --git a/products/ai_observability/frontend/evaluations/llmEvaluationLogic.ts b/products/ai_observability/frontend/evaluations/llmEvaluationLogic.tsindex 06d720d4494e..44913f6e641c 100644--- a/products/ai_observability/frontend/evaluations/llmEvaluationLogic.ts+++ b/products/ai_observability/frontend/evaluations/llmEvaluationLogic.ts@@ -1,11 +1,10 @@import { MakeLogicType, actions, afterMount, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'import { loaders } from 'kea-loaders'-import { combineUrl, router, urlToAction } from 'kea-router'+import { router, urlToAction } from 'kea-router'import posthog from 'posthog-js'import { lemonToast } from 'lib/lemon-ui/LemonToast'import { teamLogic } from 'scenes/teamLogic'-import { urls } from 'scenes/urls'import { MaxContextInput, createMaxContextHelpers } from '~/scenes/max/maxTypes'import { Breadcrumb } from '~/types'@@ -31,6 +30,7 @@ import {isBooleanEvaluationOutput,isLLMJudgeEvaluation,} from './evaluationCapabilities'+import { EvaluationBackTarget, getEvaluationBackTarget } from './evaluationNavigation'import { evaluationReportLogic, persistReportDraft } from './evaluationReportLogic'import { getHogEvalExample } from './hogEvalExamples'import { EvaluationTemplateKey, defaultEvaluationTemplates } from './templates'@@ -145,6 +145,7 @@ export interface llmEvaluationLogicValues {canEnable: booleancanEnableReason: string | nullevaluation: EvaluationConfig | null+ evaluationBackTarget: EvaluationBackTargetevaluationFormSubmitting: booleanevaluationLoading: booleanevaluationProviderKeyIssue: LLMProviderKey | null@@ -347,6 +348,7 @@ export interface llmEvaluationLogicMeta {key: string__keaTypeGenInternalSelectorTypes: {isNewEvaluation: (evaluationId: string) => boolean+ evaluationBackTarget: (isNewEvaluation: boolean, searchParams: Record<string, any>) => EvaluationBackTargetmodelSelectionRequired: (evaluation: EvaluationConfig | null,originalEvaluation: EvaluationConfig | null,@@ -379,7 +381,12 @@ export interface llmEvaluationLogicMeta {filteredEvaluationRuns: EvaluationRun[],evaluationSummaryFilter: EvaluationSummaryFilter) => number- breadcrumbs: (evaluation: EvaluationConfig | null, searchParams: Record<string, any>) => Breadcrumb[]+ breadcrumbs: (+ evaluation: EvaluationConfig | null,+ isNewEvaluation: boolean,+ evaluationBackTarget: EvaluationBackTarget,+ searchParams: Record<string, any>+ ) => Breadcrumb[]maxContext: (evaluation: EvaluationConfig | null) => MaxContextInput[]}}@@ -808,7 +815,7 @@ export const llmEvaluationLogic = kea<llmEvaluationLogicType>([updated_at: new Date().toISOString(),}const newEvaluation: EvaluationConfig =- props.evaluationType === 'sentiment'+ props.evaluationType === 'sentiment' || template?.evaluation_type === 'sentiment'? {...baseFields,evaluation_type: 'sentiment' as const,@@ -970,7 +977,7 @@ export const llmEvaluationLogic = kea<llmEvaluationLogicType>([const reportConfigStillLoading =!isNew && reportLogic.values.reportsLoading && !reportLogic.values.activeReportif (reportConfigStillLoading) {- router.actions.push(urls.aiObservabilityEvaluations(), router.values.searchParams)+ router.actions.push(getEvaluationBackTarget(false, router.values.searchParams).path)return}@@ -989,7 +996,7 @@ export const llmEvaluationLogic = kea<llmEvaluationLogicType>([}}- router.actions.push(urls.aiObservabilityEvaluations(), router.values.searchParams)+ router.actions.push(getEvaluationBackTarget(false, router.values.searchParams).path)} catch (error) {const message = evaluationErrorMessage(error, 'Failed to save evaluation')lemonToast.error(message)@@ -1029,6 +1036,12 @@ export const llmEvaluationLogic = kea<llmEvaluationLogicType>([selectors({isNewEvaluation: [(_, props) => [props.evaluationId], (evaluationId: string) => evaluationId === 'new'],+ evaluationBackTarget: [+ (s) => [s.isNewEvaluation, router.selectors.searchParams],+ (isNewEvaluation: boolean, searchParams: Record<string, any>): EvaluationBackTarget =>+ getEvaluationBackTarget(isNewEvaluation, searchParams),+ ],+modelSelectionRequired: [(s, props) => [s.evaluation, s.originalEvaluation, props.evaluationId],(@@ -1153,20 +1166,31 @@ export const llmEvaluationLogic = kea<llmEvaluationLogicType>([],breadcrumbs: [- (s) => [s.evaluation, router.selectors.searchParams],- (evaluation: EvaluationConfig | null, searchParams: Record<string, any>): Breadcrumb[] => [- {- name: 'Evaluations',- path: combineUrl(urls.aiObservabilityEvaluations(), searchParams).url,- key: 'AIObservabilityEvaluations',- iconType: 'llm_evaluations',- },- {- name: evaluation?.name || 'New Evaluation',- key: 'AIObservabilityEvaluationEdit',- iconType: 'llm_evaluations',- },- ],+ (s) => [s.evaluation, s.isNewEvaluation, s.evaluationBackTarget, router.selectors.searchParams],+ (+ evaluation: EvaluationConfig | null,+ isNewEvaluation: boolean,+ evaluationBackTarget: EvaluationBackTarget,+ searchParams: Record<string, any>+ ): Breadcrumb[] => {+ const evaluationsTarget = getEvaluationBackTarget(false, searchParams)+ const parentBreadcrumbs: Breadcrumb[] =+ isNewEvaluation && evaluationBackTarget.name !== 'Evaluations'+ ? [+ ...(evaluationBackTarget.name === 'Templates' ? [evaluationsTarget] : []),+ evaluationBackTarget,+ ]+ : [evaluationsTarget]++ return [+ ...parentBreadcrumbs,+ {+ name: evaluation?.name || 'New Evaluation',+ key: 'AIObservabilityEvaluationEdit',+ iconType: 'llm_evaluations',+ },+ ]+ },],maxContext: [diff --git a/products/ai_observability/frontend/evaluations/templates.ts b/products/ai_observability/frontend/evaluations/templates.tsindex b75f411ff9d5..65e04b4770cd 100644--- a/products/ai_observability/frontend/evaluations/templates.ts+++ b/products/ai_observability/frontend/evaluations/templates.ts@@ -1,12 +1,22 @@import { getHogEvalExample } from './hogEvalExamples'+export type EvaluationTemplateIcon =+ | 'target'+ | 'thumbs-up'+ | 'eye'+ | 'alert-triangle'+ | 'code'+ | 'search'+ | 'wrench'+ | 'emoji'+export interface LLMJudgeTemplate {key: stringname: stringdescription: stringevaluation_type: 'llm_judge'prompt: string- icon: 'target' | 'thumbs-up' | 'eye' | 'alert-triangle' | 'code'+ icon: EvaluationTemplateIcon}export interface HogTemplate {@@ -15,12 +25,51 @@ export interface HogTemplate {description: stringevaluation_type: 'hog'source: string- icon: 'target' | 'thumbs-up' | 'eye' | 'alert-triangle' | 'code'+ icon: EvaluationTemplateIcon+}++export interface SentimentTemplate {+ key: string+ name: string+ description: string+ evaluation_type: 'sentiment'+ icon: EvaluationTemplateIcon}-export type EvaluationTemplate = LLMJudgeTemplate | HogTemplate+export type EvaluationTemplate = LLMJudgeTemplate | HogTemplate | SentimentTemplateexport const defaultEvaluationTemplates: readonly EvaluationTemplate[] = [+ {+ key: 'sentiment',+ name: 'Sentiment analysis',+ description: "Classify the sentiment of the user's last message on each generation",+ evaluation_type: 'sentiment',+ icon: 'emoji',+ },+ {+ key: 'cost_latency',+ name: 'Cost & latency',+ description: 'Flag expensive or slow generations and traces using Hog code',+ evaluation_type: 'hog',+ icon: 'code',+ source: getHogEvalExample('cost_latency').source,+ },+ {+ key: 'contains_keyword',+ name: 'Contains keyword',+ description: 'Check the output contains required keywords using Hog code',+ evaluation_type: 'hog',+ icon: 'search',+ source: getHogEvalExample('contains_keywords').source,+ },+ {+ key: 'tools_called',+ name: 'Tools called',+ description: 'Check that specific tools were called using Hog code',+ evaluation_type: 'hog',+ icon: 'wrench',+ source: getHogEvalExample('tools_called').source,+ },{key: 'relevance',name: 'Relevance',@@ -45,14 +94,6 @@ export const defaultEvaluationTemplates: readonly EvaluationTemplate[] = [- If the response attempts to assist but provides limited or unclear guidance, return true- If the response is dismissive, unhelpful, or provides no value to the user, return false`,},- {- key: 'cost_latency',- name: 'Cost & latency',- description: 'Flag expensive or slow generations and traces using Hog code',- evaluation_type: 'hog',- icon: 'code',- source: getHogEvalExample('cost_latency').source,- },{key: 'hallucination',name: 'Hallucination',diff --git a/products/ai_observability/frontend/tabs/AIObservabilitySentiment.tsx b/products/ai_observability/frontend/tabs/AIObservabilitySentiment.tsxindex 7c50e87d505e..f884bfd7d1e6 100644--- a/products/ai_observability/frontend/tabs/AIObservabilitySentiment.tsx+++ b/products/ai_observability/frontend/tabs/AIObservabilitySentiment.tsx@@ -258,7 +258,12 @@ function SentimentEvaluationOnboarding(): JSX.Element {<LemonButtontype="primary"icon={<IconPlus />}- to={combineUrl(urls.aiObservabilityEvaluation('new'), { type: 'sentiment' }).url}+ to={+ combineUrl(urls.aiObservabilityEvaluation('new'), {+ type: 'sentiment',+ returnTo: urls.aiObservabilitySentiment(),+ }).url+ }data-attr="llma-sentiment-create-evaluation">Create sentiment evaluation