-
Notifications
You must be signed in to change notification settings - Fork 165
feat: add configurable row limit for AI query tools #8741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add AIQueryRowLimit config option (default 500 rows) to prevent AI agents from pulling too much data into context, which can cause context window overflow. Changes: - Add AIQueryRowLimit to InstanceConfig (configurable via rill.ai.query_row_limit) - Update query_metrics_view to cap results at AIQueryRowLimit - Update query_sql to use configurable limit instead of hardcoded 1000 - Update tool specs to document the 500 row limit - Add test for row limit enforcement https://claude.ai/code/session_01NtYNgGmYmZoy9tYya9q5ws
runtime/ai/metrics_view_query.go
Outdated
| • 'time_range' is inclusive of start time, exclusive of end time | ||
| • 'time_range.time_dimension' (optional) specifies which time column to filter; defaults to the metrics view's default time column | ||
| • Include 'sort' and 'limit' parameters to optimize query performance and avoid unbounded result sets | ||
| • Results are capped at 500 rows maximum to prevent context overflow; use filters and aggregations to reduce result size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Load number from instance config instead of hard coding
runtime/ai/metrics_view_query.go
Outdated
|
|
||
| // Cap the limit to prevent AI queries from pulling too many rows | ||
| if cfg.AIQueryRowLimit > 0 { | ||
| args = capLimit(args, cfg.AIQueryRowLimit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the limit in the resolver args (args, not props), and consume it in runtime/resolvers/metrics.go resolver implementation instead of having a hacky util function in this file.
runtime/ai/query_sql.go
Outdated
| Name: QuerySQLName, | ||
| Title: "Query SQL", | ||
| Description: "Execute a raw SQL query against an OLAP connector to introspect data.", | ||
| Description: "Execute a raw SQL query against an OLAP connector to introspect data. Results are capped at 500 rows maximum to prevent context overflow; use LIMIT, WHERE, or aggregations to reduce result size.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as for the metrics query tool
runtime/ai/query_sql.go
Outdated
| // Apply the AI query row limit (default 500) | ||
| limit := cfg.AIQueryRowLimit | ||
| if limit <= 0 { | ||
| limit = 500 // Fallback default | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't repeat the default cap here, it's already in the config defaults. Just pass the value through.
- Move limit cap logic from metrics_view_query.go to resolvers/metrics.go - Pass limit_cap via resolver args instead of using hacky util function - Remove hardcoded "500" from tool spec descriptions - Remove fallback default in query_sql.go, just pass config value through https://claude.ai/code/session_01NtYNgGmYmZoy9tYya9q5ws
Adds an AI query row cap config option to prevent AI agents
from pulling too much data into context.
The row limit is configurable with rill.ai.query_row_limit (default 500).