{"id":100907,"plugin_id":"plugin_asdk_app_6aed717b263c81918b5bf19b95d3f38b","kind":"skill","collection_source":"plugin_package","comparison_source":null,"observed_at":"2026-11-17T06:14:58.329Z","digest":"8f7de14594bea0cdd4b74482b5da58f8925ff4b185011042f7c3f61cdf6c7588","against":null,"payload":{"description":"Translate explicit data requests into Cube.dev SQL and return results. Default skill for query-type asks in the Attribution domain. No estimation, no fabrication, no proactive dashboards.","included_files":[{"relative_path":"examples/example-A-meta-roas-last-week.md","size_in_bytes":2676},{"relative_path":"references/attribution-model.md","size_in_bytes":2147},{"relative_path":"references/edge-cases.md","size_in_bytes":2822},{"relative_path":"references/failure-modes.md","size_in_bytes":2685},{"relative_path":"references/granularity-default.md","size_in_bytes":409},{"relative_path":"references/sales-platform-scope.md","size_in_bytes":4499},{"relative_path":"references/sql-examples.md","size_in_bytes":7743},{"relative_path":"references/time-range-resolution.md","size_in_bytes":1692},{"relative_path":"templates/01-channel-roas.txt","size_in_bytes":705},{"relative_path":"templates/02-top-n-campaigns.txt","size_in_bytes":655},{"relative_path":"templates/03-period-over-period.txt","size_in_bytes":1547},{"relative_path":"templates/04-creative-headlines.txt","size_in_bytes":779},{"relative_path":"templates/05-actual-store-sales.txt","size_in_bytes":718}],"name":"attribution-data-query","skill_md_contents":"---\nname: attribution-data-query\ndescription: Translate explicit data requests into Cube.dev SQL and return results. Default skill for query-type asks in the Attribution domain. No estimation, no fabrication, no proactive dashboards.\nmetadata:\n  category: attribution\n  risk: R0\n  version: 1.4.0\n  last-updated: 2026-09-23\n  references:\n  - references/time-range-resolution.md\n  - references/attribution-model.md\n  - references/sales-platform-scope.md\n  - references/granularity-default.md\n  - references/sql-examples.md\n  - references/edge-cases.md\n  - references/failure-modes.md\n  templates:\n  - templates/01-channel-roas.txt\n  - templates/02-top-n-campaigns.txt\n  - templates/03-period-over-period.txt\n  - templates/04-creative-headlines.txt\n  - templates/05-actual-store-sales.txt\n  examples:\n  - examples/example-A-meta-roas-last-week.md\n---\n\n# attribution-data-query\n\n## 1. Purpose\n\nTranslate the user's explicit data request into a precise Cube.dev SQL query and return results. **No estimation, no fabrication, no proactive dashboard creation.** This is the default skill for all query-type requests in the Attribution domain.\n\n## 2. When to trigger\n\n**Trigger condition**: the user's request explicitly states (or strongly implies) **most** of:\n\n- A specific metric (ROAS, spend, new_customers, conversion_rate, etc.)\n- A specific dimension (channel, campaign, creative, sales_channel)\n- A time range (explicit or common phrasing like \"last week\", \"last 30 days\")\n- Optional: filters, attribution model, sort order\n\n**Examples that should NOT trigger — route to another skill instead**:\n\n| Input pattern | Route to |\n|---|---|\n| Ambiguous request (\"Show me my numbers\" / \"How is Meta doing\") | `attribution-intent-clarification` |\n| \"Why\" question (\"Why did sales drop?\") | `attribution-anomaly-diagnosis` |\n| Comparing 2+ attribution models (\"Compare iDDA vs last_click\") | `attribution-model-comparison` |\n| Business-label dimension (\"by region\" / \"by audience\" / \"by brand\") | `attribution-custom-dimension` |\n| \"Create / build a dashboard\" | build a live-data dashboard **artifact** — the `dashboard` skill (an html/react live view), not a native platform dashboard. For a **recurring business review** (\"weekly overview\", \"monthly review\"), build the same live view with the prior period alongside for comparison |\n| \"Send me a weekly/daily report\" | Build the live view, then explain that scheduled delivery isn't available in this plugin yet; the user can set it up in the WorkMagic app |\n\n## 3. Inputs\n\n**Fields to parse from user input**:\n\n| Field | Required? | Description / default |\n|---|---|---|\n| dataset | Required | One of: channel_attribution (by channel) / ads_attribution (by campaign/ad) / creative_attribution (by creative) / order_sales (raw orders, no attribution split). Infer from user phrasing; never ask user to pick a DataSet name. |\n| metric | Required | Extract from user input. Always call dashboard-metrics-list to validate the field name before using it. Never guess. |\n| dimension | Required | Validate against dashboard-metrics-list. For ads_attribution / creative_attribution with NC dimensions (Product Group, Asset Type, Creator name, etc.), pass tenantId to fan out tenant-specific propertyNames. |\n| time_range | Has default | Default: past 7 days. When user doesn't specify, use the default and inform them in one sentence (\"Defaulting to the past 7 days — let me know if you want a different window\"). Do not ask back. |\n| attribution_model | Has default | Resolved per §3.2. Filter via WHERE attr_model_name = '<resolved>'. |\n| sales_platform_scope | Has default | **Default: all sales platforms** — use `attr_all_sales` / `attr_all_orders`, NOT Shopify-only. Use `attr_shopify_sales` only when the user explicitly asks for Shopify / DTC alone. Per-platform breakdown via the dedicated measures → `references/sales-platform-scope.md`. |\n| filters | Optional | Extract from input (\"only Meta\", \"ROAS > 2\", \"exclude test\"). |\n| order_by / limit | Optional | \"top 10\" / \"most\" implies sorting — order descending by the implied key. |\n\n**Default resolution rules** (see references for details):\n\n- **Time range**: always re-fetch today's date silently; comparison windows must be length-aligned → `references/time-range-resolution.md`\n- **Granularity**: auto-pick by window size, do not ask → `references/granularity-default.md`\n\n## 4. SOP\n\n**Step 1: Parse the request**\n\nMap natural language into the input fields. Resolve silently: today's date (re-fetch — never hard-code) → time window → attribution model → sales-platform scope (default all platforms, `attr_all_*`) → DataSet → dimensions → metrics.\n\n**Step 2: Pick the DataSet (by dimension)**\n\n- By channel → `channel_attribution`\n- By campaign / ad set / ad → `ads_attribution`\n- By creative / asset → `creative_attribution`\n- Pure sales / orders / no channel split → `order_sales`\n- \"campaigns spent the most\" → **not** channel; use `ads_attribution`\n- `lift_test_result` exists but belongs to lift-test domain — route there if user asks about lift test results\n\n**Step 3: `database-query-ask` first (MANDATORY)**\n\nAsk `database-query-ask` about the warehouse's Cube.dev schema patterns. `database-query-run` requires the `ctx` timestamp it produces. **Skipping fails execution.**\n\n**Step 4: Validate fields via `dashboard-metrics-list`**\n\n- Confirm metric / dimension field names exist on the chosen DataSet\n- For aliases (\"POAS\", \"return on ad spend\") → find closest match. If none, ask once.\n- **For NC dimensions on `ads_attribution` / `creative_attribution`**: pass `tenantId` to fan out tenant-specific propertyNames (e.g., `Product Group`, `Asset Type`). Use propertyName **exactly as returned (case-sensitive)**.\n\n**Step 5: Construct & execute SQL via `database-query-run`**\n\n> 🛑 **HARD RULE — copy a template first, then fill placeholders**\n>\n> BEFORE writing any SQL, you **MUST** match the user's query pattern to one of the 5 templates in `templates/`:\n> - `templates/01-channel-roas.txt` — single-platform channel-level ROAS\n> - `templates/02-top-n-campaigns.txt` — Top-N campaigns by metric\n> - `templates/03-period-over-period.txt` — WoW / MoM comparison (2 separate queries)\n> - `templates/04-creative-headlines.txt` — creative-level (JSON-array headlines)\n> - `templates/05-actual-store-sales.txt` — actual store sales (NOT attribution)\n>\n> **Copy the template, then fill placeholders** (`<tenant_id>` / `<attr_model>` / `<platform>` / `<start_date>` / `<end_date>`). Do NOT write SQL from scratch — past agents have produced wrong queries (case-sensitive platform names, missing `HAVING SUM(ad_spend) > 0`, average-of-ratios ROAS, window functions Cube rejects).\n>\n> If none of the 5 templates fit — pause and tell the user what's requested is outside the verified set, ask CSM, do NOT improvise. Pitfalls + when-to-use guidance for each template → `references/sql-examples.md`. Full worked walkthrough → `examples/example-A-meta-roas-last-week.md`.\n\n> 💡 **Don't take the bait — never average ROAS across rows**\n>\n> Tempting design: when comparing campaigns / days, compute ROAS per row first, then average. **Don't.** That's \"average of ratios\" and is mathematically wrong — a \\$64-spend campaign with one lucky order produces 122.76x ROAS that buries real top performers (vs the correct ratio-of-sums 3.44x).\n>\n> **Always** `SUM(sales) / NULLIF(SUM(spend), 0)` at the final aggregation level. Same applies to CAC, ROAS, conversion rate — any ratio metric.\n\n- Cube.dev SQL syntax only (no raw warehouse SQL, no CTE / UNION / window functions)\n- Pass the `ctx` timestamp from Step 3 (ISO 8601)\n- WHERE clauses must reflect user filter intent (incl. `NOT LIKE` / `NOT IN`)\n- Aggregation granularity must match user intent (\"spend > 1000\" defaults to total per campaign, not per-day)\n- Percentages → decimals (\"> 5%\" = 0.05)\n- Model filter uses `attr_model_name` dimension\n- Time-comparison → 2 separate queries with length-aligned windows (Cube SQL has no UNION / CTE / LAG)\n- **5 verified SQL templates** covering channel ROAS / Top-N campaigns / WoW comparison / creative headlines / actual store sales → `references/sql-examples.md`. **Required reading before writing SQL.**\n\n**Step 6: Return results**\n\n- Small (≤ 20 rows): table\n- Large: top N summary\n- One-sentence brief reading (what's high / low). **No long-form analysis.**\n- **Transparent defaults**: state the time window in business language; state attribution model only if it differs from tenant default or user specified; state granularity only if surprising\n- **Don't proactively ask** \"save as dashboard?\" — UI exposes that\n\n## 5. Tools used\n\n| Tool | Required? | Purpose |\n|---|---|---|\n| database-query-ask | Required (first) | Consult Cube.dev schema patterns before SQL. |\n| dashboard-metrics-list | Required | Validate metric / dimension field names exist on the chosen DataSet. |\n| database-query-run | Required | Execute the Cube.dev SQL query. |\n| tenant-list | Optional | Look up tenantId when needed to fan out NC dimensions on dashboard-metrics-list. |\n\n## 6. Output format\n\n- **Simple pull → chat; report-shaped → a live artifact.** A single number / single\n  metric / tiny table = answer in chat (below). But if the result is a **breakdown, a\n  trend over time, multi-channel / multi-platform, or a comparison** — anything a\n  person would screenshot and send to their boss — build it as a **live-data dashboard\n  artifact** (the `dashboard` skill: an html/react view wired to the data), not a wall\n  of table dumped in chat. Carry the same measurement identity (sales-platform scope +\n  model) onto the artifact. When in doubt between the two, a clean chat table is fine —\n  don't force an artifact for a genuinely simple ask.\n- **Table first** (for the chat path): small result sets (≤ 20 rows) shown directly\n- **Top-N summary**: large sets → top 10 / 20 with \"N total rows\" note\n- **One-line reading**: what's high / low (≤ 2 sentences)\n- **Transparent defaults**: state which defaults applied (window, model, sales-platform scope)\n- **Cite the data source** in business language at end — **sales-platform scope + attribution model** + data-as-of window (e.g. \"Source: all sales platforms, data-driven attribution, last 7 days ending Jul 20\"). **State the sales-platform scope every time**, the same way the model is stated — a sales / ROAS figure is ambiguous without it (all-platform vs Shopify-only read very differently) → `references/sales-platform-scope.md`. **Never print the raw DataSet technical name** (`channel_attribution` / `ads_attribution` / `creative_attribution` / `order_sales`) — see rule 8 below; those are internal identifiers, not customer-facing labels\n- **Don't pad with a \"save as dashboard?\" prompt** — a report-shaped result just\n  becomes the live artifact above; a simple one stays in chat\n- **No long analysis** — that's `attribution-anomaly-diagnosis`\n\n## 7. CRITICAL rules (top 8 — full list in references/failure-modes.md)\n\n1. **Always match the query to a verified SQL template in** `references/sql-examples.md` **BEFORE writing SQL** — do not write SQL from scratch. The 5 templates cover channel ROAS / Top-N campaigns / WoW comparison / creative headlines / actual store sales. If none fit, pause and ask CSM; do not improvise.\n2. **Never skip `database-query-ask` before SQL** — `database-query-run` requires the `ctx` it produces; will fail at execution\n3. **Never skip `dashboard-metrics-list`** — guessing field names causes SQL errors / wrong data\n4. **Never use raw warehouse SQL** — Cube.dev syntax only (no CTE, UNION, subqueries, LAG, window functions)\n5. **Never silently switch the attribution model** — if user said \"last_click\", don't replace it. Never lecture.\n6. **Never run iDDA without lift test data** — tell user, offer DDA, then proceed after confirm\n7. **Never hard-code today's date** from training data or earlier in conversation — always re-fetch\n8. **Never expose DataSet technical names** (`channel_attribution` / `ads_attribution` etc.) to user\n9. **Never compare full month vs full month mid-period** — use MTD vs same-day prior MTD; misaligned windows make ~50% drops appear that aren't real\n\n## 8. Edge cases & routing\n\nFull edge case & routing catalog → `references/edge-cases.md`\n\n## 9. Related skills\n\n| Skill | Relationship |\n|---|---|\n| attribution-intent-clarification | Upstream: handles ambiguous requests, then routes back to data-query once clarified |\n| attribution-anomaly-diagnosis | Downstream: handles \"why\" questions |\n| attribution-model-comparison | Downstream: handles multi-model comparisons |\n| attribution-custom-dimension | Downstream: handles business-label dimensions that require Naming Convention config |\n| attribution-edge-routing | Downstream: handles requests outside the Attribution domain's capability |\n"},"changes":[],"summary":"First saved snapshot. No earlier version is available for comparison.","summary_kind":"deterministic","summary_metadata":{}}