query-writing

Viết và thực thi các truy vấn SQL từ SELECT đơn giản đến JOIN nhiều bảng phức tạp, tổng hợp và truy vấn con. Sử dụng khi người dùng yêu cầu truy vấn cơ sở dữ liệu,…

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)

Thêm skills từ langchain-ai

deepagents-thread-inspector
langchain-ai
Kiểm tra và giải thích các cuộc hội thoại trong kho lưu trữ phiên SQLite cục bộ của Deep Agents Code. Sử dụng như phương án dự phòng khi công cụ theo dõi LangSmith không khả dụng, cho…
deepagents-python-quickstart
langchain-ai
Tạo khung một Deep Agent cục bộ tối thiểu bằng Python bằng cách làm theo hướng dẫn khởi động nhanh chính thức, sử dụng tìm kiếm web gốc của nhà cung cấp thay vì Tavily. Sử dụng khi người dùng muốn…
deepagents-typescript-quickstart
langchain-ai
Tạo khung một Deep Agent tối thiểu cục bộ bằng TypeScript theo hướng dẫn khởi động nhanh chính thức, sử dụng tìm kiếm web gốc của nhà cung cấp thay vì Tavily. Sử dụng khi người dùng…
eval-engineering
langchain-ai
Lặp lại kiểm tra kho lưu trữ agent và các dấu vết do người dùng cung cấp tùy chọn, phỏng vấn người dùng, và tạo, chạy, cũng như kiểm toán các đánh giá Harbor từng cái một. Sử dụng cho…
LangChain RAG Pipeline
langchain-ai
GỌI KỸ NĂNG NÀY khi xây dựng BẤT KỲ hệ thống tạo sinh tăng cường truy xuất (RAG) nào. Bao gồm bộ tải tài liệu, RecursiveCharacterTextSplitter, embeddings (OpenAI),…
LangChain Structured Output & HITL
langchain-ai
langchain-structured-output-&-hitl — một kỹ năng có thể cài đặt cho các tác nhân AI, được xuất bản bởi langchain-ai/langchain-skills.
LangSmith Datasets
langchain-ai
GỌI KỸ NĂNG NÀY khi tạo bộ dữ liệu đánh giá từ trace HOẶC tải bộ dữ liệu lên LangSmith HOẶC truy vấn bộ dữ liệu. Bao gồm các loại bộ dữ liệu (final_response,…
langsmith-evaluator
langchain-ai
GỌI KỸ NĂNG NÀY khi xây dựng pipeline đánh giá cho LangSmith. Bao gồm ba thành phần cốt lõi: (1) Tạo Evaluator - LLM-as-Judge, mã tùy chỉnh; (2)…