Skip to content

Commit af31ac9

Browse files
docs: clarify that cube-level ai_context does not propagate to views (#10715)
* Clarify that cube-level ai_context does not propagate to views Generated-By: mintlify-agent * docs: clarify ai_context is only consumed on views and members Made-with: Cursor --------- Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> Co-authored-by: Artyom Keydunov <artyom.keydunov@gmail.com>
1 parent eeb5b59 commit af31ac9

1 file changed

Lines changed: 137 additions & 74 deletions

File tree

docs-mintlify/docs/data-modeling/ai-context.mdx

Lines changed: 137 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -81,31 +81,95 @@ query generation.
8181
If you want to provide context to the AI agent **without exposing it in the
8282
user interface**, use the `ai_context` key inside the
8383
[`meta`][ref-cube-meta] parameter. The `meta` parameter accepts custom
84-
metadata on cubes, views, measures, and dimensions.
84+
metadata on views, measures, and dimensions.
85+
86+
<Note>
87+
88+
`ai_context` must be defined on **views** or on **individual members**
89+
(measures, dimensions). `ai_context` defined at the cube level is **not
90+
consumed by the AI agent**.
91+
92+
</Note>
93+
94+
Use `ai_context` on [views][ref-view-meta] to provide high-level guidance,
95+
and on individual members for member-specific instructions:
8596

8697
<CodeGroup>
8798

8899
```yaml title="YAML"
89-
cubes:
90-
- name: orders
91-
sql_table: orders
92-
description: All orders
100+
views:
101+
- name: revenue_overview
102+
description: Revenue metrics and breakdowns
93103
meta:
94104
ai_context: >
95-
This cube contains all e-commerce orders. When users ask about
96-
revenue, prefer the total_revenue measure which filters for
97-
completed orders only. The amount column includes tax.
105+
This is the primary view for revenue analysis. It combines
106+
order, product, and user data. Use this view when users ask
107+
about sales, revenue, or product performance.
108+
109+
cubes:
110+
- join_path: order_items
111+
includes:
112+
- total_sale_price
113+
- count
114+
- status
115+
- created_at
116+
- join_path: order_items.products
117+
includes:
118+
- brand
119+
- category
120+
```
121+
122+
```javascript title="JavaScript"
123+
view(`revenue_overview`, {
124+
description: `Revenue metrics and breakdowns`,
125+
meta: {
126+
ai_context: `This is the primary view for revenue analysis. It combines
127+
order, product, and user data. Use this view when users ask about
128+
sales, revenue, or product performance.`
129+
},
130+
131+
cubes: [
132+
{
133+
join_path: order_items,
134+
includes: [
135+
`total_sale_price`,
136+
`count`,
137+
`status`,
138+
`created_at`
139+
]
140+
},
141+
{
142+
join_path: order_items.products,
143+
includes: [
144+
`brand`,
145+
`category`
146+
]
147+
}
148+
]
149+
})
150+
```
151+
152+
</CodeGroup>
153+
154+
For member-level context, define `ai_context` directly on the measure or
155+
dimension:
156+
157+
<CodeGroup>
158+
159+
```yaml title="YAML"
160+
cubes:
161+
- name: order_items
162+
sql_table: ECOMMERCE.ORDER_ITEMS
98163

99164
measures:
100-
- name: total_revenue
101-
sql: amount
165+
- name: total_sale_price
166+
sql: sale_price
102167
type: sum
103-
filters:
104-
- sql: "{CUBE}.status = 'completed'"
168+
format: currency
105169
meta:
106170
ai_context: >
107171
Use this measure for any revenue-related questions.
108-
This excludes pending and cancelled orders.
172+
It includes all line items regardless of order status.
109173
110174
dimensions:
111175
- name: created_at
@@ -114,28 +178,21 @@ cubes:
114178
meta:
115179
ai_context: >
116180
This is the order creation timestamp in UTC.
117-
For fiscal year reporting, use the completed_at
118-
dimension instead.
181+
For delivery analysis, use delivered_at instead.
119182
```
120183
121184
```javascript title="JavaScript"
122-
cube(`orders`, {
123-
sql_table: `orders`,
124-
description: `All orders`,
125-
meta: {
126-
ai_context: `This cube contains all e-commerce orders. When users ask
127-
about revenue, prefer the total_revenue measure which filters for
128-
completed orders only. The amount column includes tax.`
129-
},
185+
cube(`order_items`, {
186+
sql_table: `ECOMMERCE.ORDER_ITEMS`,
130187

131188
measures: {
132-
total_revenue: {
133-
sql: `amount`,
189+
total_sale_price: {
190+
sql: `sale_price`,
134191
type: `sum`,
135-
filters: [{ sql: `${CUBE}.status = 'completed'` }],
192+
format: `currency`,
136193
meta: {
137194
ai_context: `Use this measure for any revenue-related questions.
138-
This excludes pending and cancelled orders.`
195+
It includes all line items regardless of order status.`
139196
}
140197
}
141198
},
@@ -146,8 +203,7 @@ cube(`orders`, {
146203
type: `time`,
147204
meta: {
148205
ai_context: `This is the order creation timestamp in UTC.
149-
For fiscal year reporting, use the completed_at
150-
dimension instead.`
206+
For delivery analysis, use delivered_at instead.`
151207
}
152208
}
153209
}
@@ -156,44 +212,55 @@ cube(`orders`, {
156212

157213
</CodeGroup>
158214

159-
You can also use `ai_context` on [views][ref-view-meta]:
215+
You can also override member-level `ai_context` when including members in
216+
a view — for example, to define synonyms or acronyms that only apply in the
217+
context of that view:
160218

161219
<CodeGroup>
162220

163221
```yaml title="YAML"
164222
views:
165-
- name: revenue_overview
166-
description: Revenue metrics and breakdowns
223+
- name: sales_overview
224+
description: Sales metrics and breakdowns
167225
meta:
168226
ai_context: >
169-
This is the primary view for revenue analysis. It combines
170-
order and product data. Use this view when users ask about
171-
sales, revenue, or product performance.
227+
This view is for sales performance analysis across brands.
172228
173229
cubes:
174-
- join_path: orders
230+
- join_path: order_items
175231
includes:
176-
- total_revenue
177-
- created_at
178-
- status
232+
- total_sale_price
233+
- join_path: order_items.products
234+
includes:
235+
- name: brand
236+
meta:
237+
ai_context: >
238+
Common acronyms: LC = Lucky Charms,
239+
HNC = Honey Nut Cheerios.
179240
```
180241
181242
```javascript title="JavaScript"
182-
view(`revenue_overview`, {
183-
description: `Revenue metrics and breakdowns`,
243+
view(`sales_overview`, {
244+
description: `Sales metrics and breakdowns`,
184245
meta: {
185-
ai_context: `This is the primary view for revenue analysis. It combines
186-
order and product data. Use this view when users ask about
187-
sales, revenue, or product performance.`
246+
ai_context: `This view is for sales performance analysis across brands.`
188247
},
189248

190249
cubes: [
191250
{
192-
join_path: orders,
251+
join_path: order_items,
252+
includes: [`total_sale_price`]
253+
},
254+
{
255+
join_path: order_items.products,
193256
includes: [
194-
`total_revenue`,
195-
`created_at`,
196-
`status`
257+
{
258+
name: `brand`,
259+
meta: {
260+
ai_context: `Common acronyms: LC = Lucky Charms,
261+
HNC = Honey Nut Cheerios.`
262+
}
263+
}
197264
]
198265
}
199266
]
@@ -208,7 +275,7 @@ view(`revenue_overview`, {
208275
| --- | --- | --- |
209276
| Visible in the UI | Yes | No |
210277
| Used by the AI agent | Yes | Yes |
211-
| Supported on | Cubes, views, measures, dimensions, segments | Cubes, views, measures, dimensions |
278+
| Supported on | Cubes, views, measures, dimensions, segments | Views, measures, dimensions |
212279

213280
Use `description` when the context is useful to both end users and the AI
214281
agent. Use `ai_context` when you want to provide additional instructions or
@@ -223,45 +290,38 @@ You can use both together. The AI agent reads both the `description` and
223290

224291
```yaml title="YAML"
225292
cubes:
226-
- name: orders
227-
sql_table: orders
228-
description: All customer orders
229-
meta:
230-
ai_context: >
231-
When users ask about "sales", they usually mean completed
232-
orders only. Prefer total_revenue over raw amount sums.
293+
- name: order_items
294+
sql_table: ECOMMERCE.ORDER_ITEMS
295+
description: Line items for all orders
233296

234297
measures:
235-
- name: total_revenue
236-
sql: amount
298+
- name: total_sale_price
299+
sql: sale_price
237300
type: sum
238-
description: Total revenue from completed orders
239-
filters:
240-
- sql: "{CUBE}.status = 'completed'"
301+
format: currency
302+
description: Total revenue across all line items
241303
meta:
242304
ai_context: >
243305
This is the primary revenue metric. Always use this
244-
instead of summing the amount dimension directly.
306+
instead of summing the sale_price column directly.
307+
When users ask about "sales", they mean this measure.
245308
```
246309
247310
```javascript title="JavaScript"
248-
cube(`orders`, {
249-
sql_table: `orders`,
250-
description: `All customer orders`,
251-
meta: {
252-
ai_context: `When users ask about "sales", they usually mean completed
253-
orders only. Prefer total_revenue over raw amount sums.`
254-
},
311+
cube(`order_items`, {
312+
sql_table: `ECOMMERCE.ORDER_ITEMS`,
313+
description: `Line items for all orders`,
255314

256315
measures: {
257-
total_revenue: {
258-
sql: `amount`,
316+
total_sale_price: {
317+
sql: `sale_price`,
259318
type: `sum`,
260-
description: `Total revenue from completed orders`,
261-
filters: [{ sql: `${CUBE}.status = 'completed'` }],
319+
format: `currency`,
320+
description: `Total revenue across all line items`,
262321
meta: {
263322
ai_context: `This is the primary revenue metric. Always use this
264-
instead of summing the amount dimension directly.`
323+
instead of summing the sale_price column directly.
324+
When users ask about "sales", they mean this measure.`
265325
}
266326
}
267327
}
@@ -277,6 +337,9 @@ cube(`orders`, {
277337
- **Use AI context for agent-specific guidance.** If you need to tell the AI
278338
agent which measure to prefer or how to interpret ambiguous terms, use
279339
`ai_context`.
340+
- **Define context on views or individual members.** `ai_context` defined
341+
at the cube level is not consumed by the AI agent. Place it on the view
342+
itself or on individual measures and dimensions.
280343
- **Be specific.** Vague context like "important metric" is less helpful than
281344
"use this measure when users ask about monthly recurring revenue."
282345
- **Document relationships.** Use AI context to explain how cubes relate to each

0 commit comments

Comments
 (0)