langchain-ai avatar

Query Writing

Structured SQL query writing skill that builds SELECTs from simple lookups to multi-table JOINs and aggregations.

CCM score
68 of 100
skills.sh installs
1.3K
GitHub stars
31.5K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers a single-table workflow (identify, check schema, query, format) and a multi-table workflow for JOINs and aggregations
  • Uses sql_db_schema for each table, sql_db_query to execute, and write_todos to plan complex tasks
  • Enforces a default LIMIT of 5, selected columns instead of SELECT *, and read-only queries with no INSERT, UPDATE, DELETE, or DROP
  • Includes error recovery steps for empty results, syntax errors, and timeouts, with a revenue-by-country example

Install

$ npx -y skills add langchain-ai/deepagents --skill query-writing -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

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.

Details

Repository
github.com/langchain-ai/deepagents
Category
Databases
First seen
May 16, 2026

More from langchain-ai/deepagents

All 12

Similar to Query Writing

More Databases