PluginBench
Skill
Official
Review
Audit score 70

query-writing

langchain-ai/deepagents

Write and execute SQL queries from simple SELECTs to complex JOINs and aggregations.

What is query-writing?

Constructs and runs SQL queries against databases, handling everything from basic single-table SELECTs to multi-table JOINs, aggregations, and subqueries. Use this when you need to retrieve, filter, or aggregate data from database tables.

  • Writes SELECT queries for single and multiple tables
  • Executes JOINs to combine data across related tables
  • Performs aggregations and GROUP BY operations
  • Handles WHERE filters, ORDER BY sorting, and LIMIT constraints
  • Plans complex queries using task breakdown before execution
  • Validates schema and column names before query construction

How to install query-writing

npx skills add https://github.com/langchain-ai/deepagents --skill query-writing
Claude Code
Cursor
Windsurf
Cline

How to use query-writing

  1. 1.Identify which table(s) contain the data you need
  2. 2.Use sql_db_schema to examine column names and types
  3. 3.For complex queries, use write_todos to plan the JOIN structure and aggregations
  4. 4.Write the SELECT query with appropriate WHERE, GROUP BY, and ORDER BY clauses
  5. 5.Execute the query using sql_db_query
  6. 6.Review results and refine if needed

Use cases

Good for
  • Retrieve customer data filtered by specific criteria
  • Generate revenue reports aggregated by country or region
  • Join invoice and customer tables to analyze spending patterns
  • Query multiple related tables to answer business questions
  • Validate data by checking for NULL values or unexpected results
Who it's for
  • Data analysts querying business databases
  • Developers building database-driven applications
  • Business users generating ad-hoc reports
  • Anyone needing to retrieve or aggregate data from SQL databases

query-writing FAQ

Can I use INSERT, UPDATE, or DELETE statements?

No. This skill only supports SELECT queries for data retrieval. DML statements are not allowed.

What should I do if a query returns no results?

Verify column names and WHERE conditions match the schema, check for case sensitivity issues, and confirm that matching data actually exists in the tables.

How do I join multiple tables?

Use INNER JOIN or LEFT JOIN with ON conditions matching foreign keys to primary keys. Examine each table's schema first to identify the correct join columns.

What's the default row limit?

Queries default to LIMIT 5 rows to avoid overwhelming result sets. Adjust as needed for your use case.

How do I handle slow or timeout queries?

Add stricter WHERE filters to reduce the result set, lower the LIMIT, or refine your query to select only necessary columns.

Full instructions (SKILL.md)

Source of truth, from langchain-ai/deepagents.


name: query-writing description: Writes and executes SQL queries from simple SELECTs to complex multi-table JOINs, aggregations, and subqueries. Use when the user asks to query a database, write SQL, run a SELECT statement, retrieve data, filter records, or generate reports from database tables.

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)