query-writing

작성자: langchain-ai

간단한 SELECT부터 복잡한 다중 테이블 JOIN, 집계, 서브쿼리까지 SQL 쿼리를 작성하고 실행합니다. 사용자가 데이터베이스 쿼리를 요청할 때 사용하세요.

npx skills add https://github.com/langchain-ai/deepagents --skill query-writing

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)

langchain-ai의 다른 스킬

deepagents-thread-inspector
langchain-ai
로컬 Deep Agents Code SQLite 세션 저장소의 대화를 검사하고 설명합니다. LangSmith 추적 도구를 사용할 수 없을 때 대체 수단으로 사용하며, …
deepagents-python-quickstart
langchain-ai
공식 퀵스타트를 따라 Python으로 최소한의 로컬 Deep Agent를 구축하고, Tavily 대신 공급자 기본 웹 검색을 사용합니다. 사용자가 다음을 원할 때 사용합니다…
deepagents-typescript-quickstart
langchain-ai
공식 퀵스타트를 따라 TypeScript로 최소한의 로컬 Deep Agent를 스캐폴드하고, Tavily 대신 제공자 네이티브 웹 검색을 사용합니다. 사용자가…
eval-engineering
langchain-ai
에이전트 저장소와 사용자가 제공한 선택적 트레이스를 반복적으로 검사하고, 사용자와 인터뷰하며, Harbor 평가를 한 번에 하나씩 생성, 실행, 감사합니다. 용도:…
LangChain RAG Pipeline
langchain-ai
이 스킬을 호출하여 검색 증강 생성(RAG) 시스템을 구축하세요. 문서 로더, RecursiveCharacterTextSplitter, 임베딩(OpenAI) 등을 다룹니다.
LangChain Structured Output & HITL
langchain-ai
langchain-structured-output-&-hitl — AI 에이전트를 위한 설치 가능한 스킬로, langchain-ai/langchain-skills에서 게시되었습니다.
LangSmith Datasets
langchain-ai
이 스킬은 평가 데이터셋을 트레이스에서 생성하거나 LangSmith에 데이터셋을 업로드하거나 데이터셋을 쿼리할 때 호출하세요. 데이터셋 유형(final_response, …)을 다룹니다.
langsmith-evaluator
langchain-ai
LangSmith 평가 파이프라인을 구축할 때 이 스킬을 호출하세요. 세 가지 핵심 구성 요소를 다룹니다: (1) 평가자 생성 - LLM-as-Judge, 사용자 정의 코드; (2)…