Skip to content

Conversation

@begelundmuller
Copy link
Contributor

@begelundmuller begelundmuller commented Feb 2, 2026

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).

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
• '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
Copy link
Contributor Author

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


// Cap the limit to prevent AI queries from pulling too many rows
if cfg.AIQueryRowLimit > 0 {
args = capLimit(args, cfg.AIQueryRowLimit)
Copy link
Contributor Author

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.

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.",
Copy link
Contributor Author

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

Comment on lines 73 to 77
// Apply the AI query row limit (default 500)
limit := cfg.AIQueryRowLimit
if limit <= 0 {
limit = 500 // Fallback default
}
Copy link
Contributor Author

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
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.

3 participants