You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(api): improve insights engine from product evaluation
- Reweight priority scoring toward actionability × business impact (prompt + Zod)
- Require prescriptive suggestions; forbid generic monitor/review fluff
- Inject last 14d insight titles per website into the prompt to cut redundant cards
- Document data boundaries (no invented funnel/MRR without metrics in query data)
- Note living-dedupe limitation in databuddy codebase-map skill
Copy file name to clipboardExpand all lines: .agents/skills/databuddy/references/codebase-map.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,7 @@ Use this file when the task spans multiple packages or when the right edit locat
19
19
20
20
- Elysia API service
21
21
- Default dev port: `3001`
22
+
- AI insights: [`apps/api/src/routes/insights.ts`](/Users/iza/Dev/Databuddy/apps/api/src/routes/insights.ts) — loads last ~14d insight titles per site into the model prompt to reduce repeat narratives; true “living” dedupe/merge would need schema or upsert work. Funnel/MRR/retention insights require those metrics in query data—do not invent in prompts alone.
22
23
- Handles routes such as public endpoints, webhooks, health, query, MCP, and agent-related APIs
"2-3 sentenceswith specific numbers from BOTH periods. Always include the actual values and the delta."
43
+
"2-3 sentences: what changed and why it might matter, with specific numbers from BOTH periods. Explain cause only when grounded in the data or annotations."
42
44
),
43
45
suggestion: z
44
46
.string()
45
47
.describe(
46
-
'One concrete, specific action. Good: "Your /blog/seo-guide drove 40% of traffic - share it on social." Bad: "Monitor your traffic."'
48
+
"Required prescriptive 'now what': one or two sentences telling the user what to do next (product, marketing, or ops). Tie to the metric (e.g. add a CTA, capture email from volatile channel, prioritize top error). Never generic: no 'monitor', 'keep watching', or 'consider reviewing' without a concrete step."
"1-10 from actionability × business impact, NOT raw % magnitude. User-facing errors, conversion/session drops, or reliability issues outrank vanity traffic spikes. A 5% drop in a meaningful engagement metric can score higher than a 70% visitor increase with no conversion context. Reserve 8-10 for issues that hurt users or revenue signals in the data."
"1-3 insights ranked by surprise-factor x impact. Focus on what changed and why it matters."
89
+
"1-3 insights ranked by actionability × business impact. Skip repeating a narrative already listed under recently reported insights unless the change is materially new."
88
90
),
89
91
});
90
92
@@ -227,21 +229,71 @@ async function fetchRecentAnnotations(websiteId: string): Promise<string> {
227
229
return`\n\nUser annotations (known events that may explain changes):\n${lines.join("\n")}`;
228
230
}
229
231
230
-
constINSIGHTS_SYSTEM_PROMPT=`You are an analytics insights engine. Your job is to find the 1-3 most significant, actionable findings from week-over-week website data.
return`\n\n## Recently reported insights for this website (avoid repeating the same narrative unless something materially changed)\n${lines.join("\n")}`;
265
+
}
266
+
267
+
constINSIGHTS_SYSTEM_PROMPT=`You are an analytics insights engine. Your job is to find the 1-3 most significant findings from week-over-week website data, written like an analyst: descriptive where needed, but every insight MUST include a prescriptive "so what / now what" in the suggestion field.
268
+
269
+
Priority scoring (priority 1-10):
270
+
- Score by actionability × business impact, NOT by how large the percentage move is. Traffic spikes without conversion or outcome context are lower priority than errors, session/engagement collapses, or clear negative trends affecting users.
271
+
- Operational health (errors, reliability) often matters more than vanity traffic growth. A moderate error-rate improvement during high traffic can be high value.
272
+
- Do not assign 8-10 to pure volume spikes unless the data also shows a linked risk or opportunity worth acting on.
- Pages: new page entering top 10 or page dropping out = notable. Individual page change >25% = significant.
237
279
- Referrers: new source appearing or major source declining >20% = notable.
238
280
281
+
Anti-redundancy:
282
+
- If the user message includes a "Recently reported insights" section, treat those as already surfaced. Do NOT output a new insight that tells the same story (same underlying signal and direction) unless the narrative would be materially different (e.g. new root cause, reversal, or threshold crossed). Prefer novel angles or omit.
283
+
284
+
Data boundaries:
285
+
- Only use metrics present in the JSON (summary, pages, errors, referrers). Do not invent funnel conversion rates, MRR, revenue, cohort retention, or signup counts unless they appear in the data.
286
+
- If conversion or goal data appears in summary_metrics, you may connect traffic to outcomes. If absent, do not fabricate funnel or revenue insights.
287
+
288
+
Suggestion field (required quality):
289
+
- Must answer "what should we do next?" in one or two sentences: concrete product, marketing, or engineering action tied to the numbers.
290
+
- Bad: "Monitor traffic", "Keep an eye on this", "Consider reviewing analytics."
291
+
- Good: tie to pages, channels, CTAs, error classes, or experiments suggested by the data.
292
+
239
293
Rules:
240
-
- Every insight MUST include specific numbers from both periods (e.g. "1,234 visitors, up from 987 last week")
241
-
- Every suggestion MUST be a concrete next step, not generic advice
242
-
- If annotations explain a change, mention it but still report the data
243
-
- If everything is stable, return ONE positive/neutral insight (e.g. "Steady at 2,400 weekly visitors")
244
-
- Rank by surprise-factor x business-impact
294
+
- Every insight MUST include specific numbers from both periods where applicable.
295
+
- If annotations explain a change, mention it but still report the data.
296
+
- If everything is stable, return ONE positive/neutral insight (e.g. "Steady at 2,400 weekly visitors") with a light suggestion if appropriate.
245
297
- Never fabricate or round numbers beyond what's in the data`;
246
298
247
299
asyncfunctionanalyzeWebsite(
@@ -255,23 +307,25 @@ async function analyzeWebsite(
0 commit comments