Engineering
query-writing avatar

query-writing

Writes, executes, and refines SQL queries, from basic selects to complex multi-table joins, aggregations, and subqueries for data retrieval and reporting.

Introduction

The query-writing skill empowers agents to interact directly with relational databases, providing a structured workflow for generating, testing, and refining SQL code. This skill is designed for data analysts, software engineers, and automated reporting systems that need to bridge the gap between natural language requests and structured database interactions. By leveraging tools like sql_db_schema for metadata discovery and sql_db_query for execution, the agent can autonomously navigate database schemas, handle multi-table relationships, and produce accurate result sets.

  • Performs comprehensive query generation ranging from simple SELECT statements to complex JOIN structures, aggregations (SUM, AVG, COUNT), and nested subqueries.

  • Implements a safety-first methodology by prioritizing read-only operations and explicitly prohibiting destructive DML commands like INSERT, UPDATE, DELETE, or DROP.

  • Utilizes a structured plan-then-act workflow, encouraging the use of write_todos to decompose complex analytical questions into manageable logical steps before execution.

  • Integrates schema inspection workflows to identify correct tables, foreign key relationships, and required fields, ensuring query accuracy before running code.

  • Features robust error recovery protocols that help the agent address common SQL issues such as empty result sets, syntax errors, and query timeouts through systematic validation and refinement.

  • Use this skill when users request data retrieval, specific record filtering, cross-table reporting, or database-driven insights.

  • Always apply sensible constraints such as LIMIT clauses (defaulting to 5 rows) to manage large result sets and ensure performance.

  • Use table aliases consistently to improve query readability and maintainability when working with complex joins.

  • For troubleshooting, treat failures as iterative cycles: verify column names against the schema, check for case sensitivity, and ensure that GROUP BY clauses include all non-aggregated columns.

  • Rely on this skill specifically within a SQL-compatible environment; it is intended for structured data retrieval rather than general file system or web search tasks.

Repository Stats

Stars
22,035
Forks
3,081
Open Issues
208
Language
Python
Default Branch
main
Sync Status
Idle
Last Synced
Apr 30, 2026, 08:09 AM
View on GitHub