Rifqi Hafizuddin Claude Opus 4.8 commited on
Commit
99aa414
·
1 Parent(s): 6bda333

fix(planner): correct top-N guidance — in-query ranking IS supported

Browse files

The prior note wrongly claimed there's no in-query "top N by an aggregate" and
steered plans to fetch grouped totals and narrate the leaders. Verified the
engine already supports it end-to-end (IRValidator + SQL and pandas compilers):
order_by accepts a select alias, so "top 3 products by revenue" compiles to a
single retrieve_data — group_by + aggregate-with-alias + order_by that alias +
limit. Replaced the guidance with the correct pattern.

Few-shot example in examples.py deferred pending a playground test of the
corrected prose.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Files changed (1) hide show
  1. src/config/prompts/planner.md +10 -6
src/config/prompts/planner.md CHANGED
@@ -78,12 +78,16 @@ only a `TaskList` object that conforms to the provided schema.
78
  - For `in`/`not_in` (value is a list) or `between` (value is `[low, high]`), it
79
  is still the ELEMENT type — a list of names is `"string"`, a date range is
80
  `"date"`. It is **never** `"list"`.
81
- - **Use only the `args` a tool lists.** There is no in-query "top N by an
82
- aggregate": `order_by` sorts by a listed column and `analyze_aggregate` takes
83
- only `data`/`aggregations`/`group_by`. For a "top/most/least by <metric>"
84
- question, retrieve the grouped totals (group_by the dimension, aggregate the
85
- measure) and let the analysis name the leaders do NOT add `order_by`/`limit`
86
- args to a tool that doesn't list them.
 
 
 
 
87
 
88
  # Output
89
 
 
78
  - For `in`/`not_in` (value is a list) or `between` (value is `[low, high]`), it
79
  is still the ELEMENT type — a list of names is `"string"`, a date range is
80
  `"date"`. It is **never** `"list"`.
81
+ - **Use only the `args` a tool lists** e.g. `analyze_aggregate` takes only
82
+ `data`/`aggregations`/`group_by`, so never add `order_by`/`limit` to it.
83
+ - **Top-N ("top/most/least N by <metric>") is a single `retrieve_data` query**,
84
+ not an `analyze_*` step. Group by the dimension and aggregate the measure with
85
+ an `alias`, then rank and cap in the same IR: put that alias in
86
+ `order_by[].column_id` (which accepts a column id OR a select alias), set `dir`
87
+ (`"desc"`/`"asc"`), and set `limit: N`. E.g. for "top 3 products by revenue":
88
+ select the product column + `sum(revenue)` aliased `total_revenue`, with
89
+ `group_by: ["<product_col_id>"]`,
90
+ `order_by: [{"column_id": "total_revenue", "dir": "desc"}]`, `limit: 3`.
91
 
92
  # Output
93