-
Notifications
You must be signed in to change notification settings - Fork 273
Open
Description
Problem
LLMs often generate invalid PromQL or LogQL queries due to syntax errors. Currently, these errors are only discovered after the query is sent to Prometheus/Loki, which:
- Wastes API calls and context window space
- Creates unnecessary iteration cycles
- Provides unclear error messages
- Slows down LLM query generation workflows
Proposed Solution
Add query validation using the official parsers from Prometheus and Loki before executing queries.
Implementation
Add validation functions using production-grade parsers:
ValidatePromQL(): Usesgithub.com/prometheus/prometheus/promql/parserValidateLogQL(): Usesgithub.com/grafana/loki/v3/pkg/logql/syntax
Integrate inline validation into existing tools:
query_prometheus: Validate PromQL before executionquery_loki_logs: Validate LogQL before execution
Dependencies
- Prometheus parser: Already available in
github.com/prometheus/prometheus - Loki parser: Add
github.com/grafana/loki/v3/pkg/logql/syntax
Benefits
- For LLMs: Reduced context usage and faster iteration
- For users: Immediate feedback on query syntax
- For API: Fewer invalid requests
- For debugging: Clear, specific error messages
Testing
Comprehensive unit tests covering valid queries, invalid syntax, and edge cases.
Alternative Considered
Creating separate validate_promql and validate_logql tools was considered, but inline validation is simpler and provides immediate feedback without additional tool calls.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels