Skip to content

fix(chat): constrain SQL row-limit placement to outermost query in prompt templates (#1202) - #1389

Merged
ulleo merged 1 commit into
mainfrom
fix/issue-1202-row-limit-placement
Sep 21, 2026
Merged

ulleo merged 1 commit into
mainfrom
fix/issue-1202-row-limit-placement

Conversation

@ulleo

@ulleo ulleo commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

The row-limit policy in query_limit/no_query_limit did not specify WHERE the limit should be applied, so LLMs could put LIMIT/ROWNUM/TOP inside subqueries, truncating the data feeding aggregation (limiting accessed rows instead of the final result set).

  • query_limit/no_query_limit: limit must be applied only to the outermost query; never inside subqueries, derived tables or CTEs; add conditional per-group top-N note (window functions where supported)
  • process_check (template.yaml + Oracle override): step 4 now verifies limit placement
  • sql_examples: add nested-aggregation bad/good examples for all 11 engines showing the limit on the outer query only
  • Oracle: fix invalid GROUP BY...WHERE ROWNUM example and wrong ROWNUM-before-ORDER BY few-shot answers (wrap with outer query)

…ompt templates (#1202)

The row-limit policy in query_limit/no_query_limit did not specify WHERE
the limit should be applied, so LLMs could put LIMIT/ROWNUM/TOP inside
subqueries, truncating the data feeding aggregation (limiting accessed
rows instead of the final result set).

- query_limit/no_query_limit: limit must be applied only to the outermost
  query; never inside subqueries, derived tables or CTEs; add conditional
  per-group top-N note (window functions where supported)
- process_check (template.yaml + Oracle override): step 4 now verifies
  limit placement
- sql_examples: add nested-aggregation bad/good examples for all 11
  engines showing the limit on the outer query only
- Oracle: fix invalid GROUP BY...WHERE ROWNUM example and wrong
  ROWNUM-before-ORDER BY few-shot answers (wrap with outer query)
@ulleo
ulleo merged commit 337c755 into main Sep 21, 2026
3 checks passed
@ulleo
ulleo deleted the fix/issue-1202-row-limit-placement branch September 21, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant