
Query Writing
- 1.1k installs
- 27.3k repo stars
- Updated August 5, 2026
- langchain-ai/deepagents
query-writing is a DeepAgents database skill that writes and executes SQL from natural language—from simple SELECTs through multi-table JOINs and aggregations—for developers retrieving data from real databases.
About
query-writing is a LangChain DeepAgents skill that converts natural-language data requests into correct, executable SQL. For simple questions the workflow identifies the target table, loads column definitions with sql_db_schema, drafts SELECT statements with WHERE, LIMIT, and ORDER BY, then runs sql_db_query and formats results. Complex requests add multi-table JOINs, aggregations, and subqueries. Developers reach for query-writing when a coding agent must answer ad-hoc reporting questions, prototype analytics queries, or debug data retrieval without hand-writing every statement against unfamiliar schemas.
- Handles both simple single-table SELECTs and complex multi-table JOINs with aggregations and subqueries
- 5-step workflow for simple queries using schema inspection before writing SQL
- 4-step complex workflow that starts with write_todos planning then examines every table schema
- Explicit validation rules for JOIN conditions, GROUP BY correctness, and filter placement
- Always uses sql_db_schema and sql_db_query tools to prevent hallucinated column or table names
Query Writing by the numbers
- 1,099 all-time installs (skills.sh)
- +43 installs in the week ending Aug 4, 2026 (Skillselion tracking)
- Ranked #86 of 911 Databases skills by installs in the Skillselion catalog
- Security screen: MEDIUM risk (skills.sh audit)
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/langchain-ai/deepagents --skill query-writingAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 1.1k |
|---|---|
| repo stars | ★ 27.3k |
| Security audit | 3 / 3 scanners passed |
| Last updated | August 5, 2026 |
| Repository | langchain-ai/deepagents ↗ |
How do you write SQL queries from natural language?
Let their coding agent reliably turn natural language requests into correct SQL that reads from real databases.
Who is it for?
Developers using DeepAgents who need reliable natural-language-to-SQL for reporting, filtering, and multi-table analytics on connected databases.
Skip if: Teams needing schema migrations, ORM model generation, or write-heavy transactional SQL without read-query guardrails.
When should I use this skill?
User asks to query a database, write SQL, run SELECT, filter records, or generate reports from tables.
What you get
Executed SQL results with formatted answers drawn from live database tables and schemas.
- executed SQL results
- formatted query answers
Files
Query Writing Skill
Workflow for Simple Queries
For straightforward questions about a single table:
1. Identify the table - Which table has the data? 2. Get the schema - Use sql_db_schema to see columns 3. Write the query - SELECT relevant columns with WHERE/LIMIT/ORDER BY 4. Execute - Run with sql_db_query 5. 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.
Example: Revenue by Country
SELECT
c.Country,
ROUND(SUM(i.Total), 2) as TotalRevenue
FROM Invoice i
INNER JOIN Customer c ON i.CustomerId = c.CustomerId
GROUP BY c.Country
ORDER BY TotalRevenue DESC
LIMIT 5;Error Recovery
If a query fails or returns unexpected results: 1. Empty results — Verify column names and WHERE conditions against the schema; check for case sensitivity or NULL values 2. Syntax error — Re-examine JOINs, GROUP BY completeness, and alias references 3. Timeout — Add stricter WHERE filters or LIMIT to reduce result set, then refine
Quality Guidelines
- Query only relevant columns (not SELECT *)
- Always apply LIMIT (5 default)
- Use table aliases for clarity
- For complex queries: use write_todos to plan
- Never use DML statements (INSERT, UPDATE, DELETE, DROP)
Related skills
How it compares
Use query-writing when an agent already has sql_db_schema and sql_db_query tools wired; use migration skills when changing schema instead of reading data.
FAQ
What database tools does query-writing use?
query-writing uses sql_db_schema to read table columns and sql_db_query to execute SELECT statements, supporting simple filters through complex JOINs, aggregations, and subqueries.
What query types does query-writing handle?
query-writing covers simple single-table SELECTs with WHERE, LIMIT, and ORDER BY, plus complex multi-table JOINs, aggregations, and subqueries generated from natural-language requests.
Is Query Writing safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.