Spaces:
Sleeping
Sleeping
Commit Β·
2e7546f
1
Parent(s): 600d2a0
status closed added
Browse files- ai/signatures.py +39 -8
ai/signatures.py
CHANGED
|
@@ -88,11 +88,29 @@ class AnalyzeAndPlan(dspy.Signature):
|
|
| 88 |
β NEVER sum gold_amount + diamond_amount from PO line tables β that misses labour.
|
| 89 |
|
| 90 |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 91 |
-
RULE 2 β STATUS FILTERING
|
| 92 |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 93 |
-
For
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 98 |
RULE 1.5 β AGGREGATION GRANULARITY (CRITICAL)
|
|
@@ -249,10 +267,23 @@ class SQLGeneration(dspy.Signature):
|
|
| 249 |
- NEVER add gold_amount + diamond_amount or any component columns β
|
| 250 |
that always gives the WRONG answer (misses labour, taxes, etc.)
|
| 251 |
|
| 252 |
-
6.
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
7. DATE FILTERING (order_date is TEXT 'YYYY-MM-DD'):
|
| 258 |
- Use the EXACT year values from the [CONTEXT] block in the question.
|
|
|
|
| 88 |
β NEVER sum gold_amount + diamond_amount from PO line tables β that misses labour.
|
| 89 |
|
| 90 |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 91 |
+
RULE 2 β STATUS FILTERING (DEFAULT = 'closed', ALWAYS)
|
| 92 |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 93 |
+
For ANY query that touches sales_table_v2_sales_order, the DEFAULT
|
| 94 |
+
is to always filter WHERE status = 'closed'.
|
| 95 |
+
|
| 96 |
+
ONLY skip or change this filter when the question EXPLICITLY mentions
|
| 97 |
+
a different status by name β e.g. "pending orders", "open orders",
|
| 98 |
+
"cancelled orders", "all orders regardless of status".
|
| 99 |
+
If the question does not mention any status word, use status = 'closed'.
|
| 100 |
+
|
| 101 |
+
This applies to every type of sales_order query:
|
| 102 |
+
β’ Revenue, AOV, total sales, order value
|
| 103 |
+
β’ Order count ("how many orders", "number of orders")
|
| 104 |
+
β’ Top customers, top products, top SKUs by any metric
|
| 105 |
+
β’ Any SUM, AVG, COUNT on total_amount, line_total, or component costs
|
| 106 |
+
β’ Any JOIN that starts from or passes through sales_order
|
| 107 |
+
β’ Component cost queries from sales_order_line_pricing
|
| 108 |
+
(join back to sales_order and apply status = 'closed')
|
| 109 |
+
|
| 110 |
+
NEVER apply status = 'closed' to:
|
| 111 |
+
β’ Purchase order tables (they have a separate status column)
|
| 112 |
+
β’ Inventory tables
|
| 113 |
+
β’ Customer master / product lookup tables (no status column)
|
| 114 |
|
| 115 |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 116 |
RULE 1.5 β AGGREGATION GRANULARITY (CRITICAL)
|
|
|
|
| 267 |
- NEVER add gold_amount + diamond_amount or any component columns β
|
| 268 |
that always gives the WRONG answer (misses labour, taxes, etc.)
|
| 269 |
|
| 270 |
+
6. STATUS = 'closed' IS THE DEFAULT FOR ALL SALES ORDER QUERIES:
|
| 271 |
+
Unless the question explicitly mentions a different status (e.g. "pending",
|
| 272 |
+
"open", "cancelled", "all orders"), ALWAYS add WHERE so.status = 'closed'.
|
| 273 |
+
This is not optional β omitting it returns incomplete/incorrect data.
|
| 274 |
+
|
| 275 |
+
Correct formulas:
|
| 276 |
+
- Revenue: SUM(so.total_amount) ... WHERE so.status = 'closed'
|
| 277 |
+
- AOV: AVG(so.total_amount) ... WHERE so.status = 'closed'
|
| 278 |
+
- Order count: COUNT(DISTINCT so.so_id) ... WHERE so.status = 'closed'
|
| 279 |
+
- Per-product rev: SUM(lp.line_total) FROM sales_order_line_pricing lp
|
| 280 |
+
JOIN sales_table_v2_sales_order so ON so.so_id = sol.so_id
|
| 281 |
+
WHERE so.status = 'closed'
|
| 282 |
+
- Component costs: SUM(lp.diamond_amount_per_unit * lp.quantity)
|
| 283 |
+
FROM sales_order_line_pricing lp
|
| 284 |
+
JOIN sales_table_v2_sales_order_line sol ON lp.sol_id = sol.sol_id
|
| 285 |
+
JOIN sales_table_v2_sales_order so ON sol.so_id = so.so_id
|
| 286 |
+
WHERE so.status = 'closed'
|
| 287 |
|
| 288 |
7. DATE FILTERING (order_date is TEXT 'YYYY-MM-DD'):
|
| 289 |
- Use the EXACT year values from the [CONTEXT] block in the question.
|