langchain-ai avatar

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-code

Installs into .claude/skills of the current project.

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.

Sponsors

Details

Repository
github.com/langchain-ai/deepagents
Categories
Backend & APIs, Documentation, AI & Agent Building, Databases
First seen
May 16, 2026

More from langchain-ai/deepagents

All 12
1langchain-ai avatarschema-explorationlangchain-ai/deepagentsLists tables, describes columns and data types, identifies foreign key relationships, and maps entity relationships in a database. Use when the user asks about 1.3Kskills.sh installs
2nvidia avatarcuopt-routing-formulationnvidia/skillsVehicle routing (VRP, TSP, PDP) — problem types and data requirements. Domain concepts; no API or interface.1.3Kskills.sh installs
3nvidia avatarnemoclaw-user-guidenvidia/skillsGuides human users' AI agents to the NemoClaw docs MCP server and canonical Fern documentation in Markdown form. Use when users ask how to install, configure, o1.3Kskills.sh installs
4quodsoler avatarue-sequencer-cinematicsquodsoler/unreal-engine-skillsUse this skill when working with Sequencer, LevelSequence, cutscene, cinematic, camera, movie scene, sequencer event, or Movie Render Queue in Unreal Engine. Se1.3Kskills.sh installs
5kostja94 avatarindexingkostja94/marketing-skillsWhen the user wants to fix indexing issues from Search Console, use noindex, or implement Google Indexing API. Also use when the user mentions "fix indexing," "1.3Kskills.sh installs
6omer-metin avatar3d-modelingomer-metin/skills-for-antigravityExpert 3D modeling specialist with deep knowledge of topology, UV mapping, game-ready and film-ready pipelines, DCC tool workflows (Blender, Maya, ZBrush, 3ds M1.3Kskills.sh installs