query-writing

query-writing is a skill for Claude Code, Codex from langchain-ai/deepagents. It costs 57 tokens per session (521 once invoked), scanned A, original, MIT.

A guide for writing and running SQL, the language used to retrieve and summarize data in databases. It covers simple queries as well as queries that combine tables, filter records, group results, and calculate totals.

In plain words
What is it for?
Retrieving records, joining related database tables, calculating summaries such as revenue by country, filtering results, and generating reports.
Why use it?
It helps turn plain-language data questions into checked queries while reducing mistakes with table relationships, filters, grouping, and sorting.

Skill for Claude CodeCodex ✓ vendor

Written for no agent in particular: nothing here depends on one.

not rated 30krepo +198 today A scan Socket: passSnyk: passSkillSpector: pass 57 tokens original MIT

Good fit Retrieving records, joining related database tables, calculating summaries such as revenue by country, filtering results, and generating reports.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/langchain-ai/deepagents/query-writing
About the project

Deep Agents is an extensible agent harness that provides an out-of-the-box agent for long, multi-step tasks, with features such as planning, sub-agents, filesystem access, context management, memory, and human approval of tool calls. It is used by developers building agents with different language models, and its catalogue entries extend the harness with reusable skills, MCP servers, and instructions.

langchain-ai/deepagents · 30,456 stars · on GitHub · docs.langchain.com

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add langchain-ai/deepagents --skill query-writing
Clone the repo
git clone --depth 1 https://github.com/langchain-ai/deepagents

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for query-writing

README.md
[![agentmods](https://agentmods.dev/badge/skills/langchain-ai/deepagents/query-writing/github.svg)](https://agentmods.dev/skills/langchain-ai/deepagents/query-writing)
Your own site
<a href="https://agentmods.dev/skills/langchain-ai/deepagents/query-writing"><img src="https://agentmods.dev/badge/skills/langchain-ai/deepagents/query-writing/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for query-writing

Your own site · 80×15
<a href="https://agentmods.dev/skills/langchain-ai/deepagents/query-writing"><img src="https://agentmods.dev/badge/skills/langchain-ai/deepagents/query-writing.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 57 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 521 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • Socket pass 17 Sept 2026
  • Snyk pass 17 Sept 2026
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00057 $0.00521
Opus 5.5 $0.00023 $0.00208
Sonnet 5.5 $0.00011 $0.00104
Haiku 4.5 $0.00006 $0.00052

Measured 1mo ago against content hash b88865cfc75c, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

query-writing scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

examples/text-to-sql-agent/skills/query-writing/SKILL.md · 69 lines

What it actually says

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)
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 69 lines · 57 tokens per session scan A b88865cfc75c

Subscribe to this mod's changes

query-writing is a skill published in the GitHub repository langchain-ai/deepagents (30,456 stars, last pushed today), licensed MIT. It adds 57 tokens to every session and 521 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

stripe-projects

Use when the user wants to provision infrastructure or third-party services using Stripe Projects. Triggers: "I need a database", "set up auth", "add caching", "give me a Postgres", "provision Redis", "I need hosting", "add a vector DB", "get me an API key for X", "get credentials for X", "sign up for a service", "set…

stripe/ai · 213 tokens

qdrant-clients-sdk

Qdrant provides client SDKs for various programming languages, allowing easy integration with Qdrant deployments.

truera/trulens · 28 tokens

adding-warehouse-person-properties

Sync columns from a synced data warehouse table onto PostHog person or group properties, so warehouse data becomes usable anywhere person and group properties already work: feature flag targeting, cohorts, insight filters and breakdowns, surveys, session replay filters, workflows, and the person profile. Use when the…

PostHog/posthog · 139 tokens

setting-up-data-catalog

Populates and maintains a project's data catalog (semantic layer): canonical metrics, trust marks (certifications) on warehouse tables/views, and reviewed table relationships. Use when asked to set up / seed / bootstrap the data catalog or semantic layer, to catalog a project's metrics, to certify or deprecate data…

PostHog/posthog · 135 tokens

setting-up-warehouse-properties

Populate person or group properties from a data warehouse table or materialized view, so warehouse columns become properties usable in feature flags, cohorts, and insights. Use when the user wants to "sync my Postgres columns to person properties", "map a warehouse table to people", "replace our daily identify cron"…

PostHog/posthog · 126 tokens

modeling-warehouse-foundations

Shared foundations for building reusable data models in PostHog, on either of two stacks: PostHog-native data-warehouse views / materialized views (HogQL, via the view- MCP tools), or an external dbt project (sources.yml + staging/marts + schema tests) run against your own or PostHog's managed warehouse. Read before…

PostHog/posthog · 231 tokens