
Query Writing
Handles SQL queries from basic SELECTs to complex multi-table JOINs with aggregations and subqueries. It follows a structured workflow: examine schemas, plan your approach with todos for complex queries, construct the JOIN logic, then validate before executing. Defaults to LIMIT 5 and read-only operations. The error recovery guidance is practical, covering empty results, syntax issues, and timeouts. What I like is the explicit planning step for complex queries. Breaking down which tables you need and mapping foreign key relationships before writing SQL prevents the usual trial-and-error mess. It won't let you run INSERT, UPDATE, or DELETE statements, so this is strictly for data retrieval and reporting.
- skills.sh installs
- 1.3K
- GitHub stars
- 31.2K
- last updated
- Aug 21, 2026
Install
$ npx -y skills add langchain-ai/deepagents --skill query-writing --agent claude-codeInstalls into .claude/skills of the current project.
Files
Query Writing Skill
Workflow for Simple Queries
For straightforward questions about a single table:
- Identify the table - Which table has the data?
- Get the schema - Use
sql_db_schemato see columns - Write the query - SELECT relevant columns with WHERE/LIMIT/ORDER BY
- Execute - Run with
sql_db_query - Format answer - Present results clearly
Workflow for Complex Queries
For questions requiring multiple tables:
1. Plan Your Approach
Use write_todos to break down the task:
- Identify all tables needed
- Map relationships (foreign keys)
- Plan JOIN structure
- Determine aggregations
2. Examine Schemas
Use sql_db_schema for EACH table to find join columns and needed fields.
3. Construct Query
- SELECT - Columns and aggregates
- FROM/JOIN - Connect tables on FK = PK
- WHERE - Filters before aggregation
- GROUP BY - All non-aggregate columns
- ORDER BY - Sort meaningfully
- LIMIT - Default 5 rows
4. Validate and Execute
Check all JOINs have conditions, GROUP BY is correct, then run query.
Sponsors
Details
- Repository
- github.com/langchain-ai/deepagents
- Categories
- Backend & APIs, Documentation, AI & Agent Building, Databases
- First seen
- May 16, 2026