sql-from-question
Skill0 starsChanged 5 months agoMITView on GitHub
Use when the user asks a question in plain English that requires querying a known database. Triggers when the user provides a schema (DDL, ER diagram description, or table list) and asks "how many...", "what is the average...", "show me users who...", or any analytical question that maps to SQL.
In this repository7 other files it gives its agents.
- api-docs-from-openapiSkill
- changelog-writerSkill
- code-review-preflightSkill
- csv-cleanerSkill
- json-schema-from-sampleSkill
- meeting-notes-summarizerSkill
- regex-builderSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 3 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Confirm you have the schema: If not provided, ask for it.
- Distinctive: line 18
If the schema is incomplete (e.g.
- Very specific: line 20
Confirm the SQL dialect: Default to PostgreSQL. Ask only if the schema or question uses dialect-specific features and you're unsure (e.g.
- Very specific: line 26
Use lowercase keywords (select, from, where) for readability in this conversation.
- Very specific: line 27
Always alias tables in joins with short, meaningful names (users u, orders o).
- Distinctive: line 28
Always qualify columns with table aliases when more than one table is involved.
- Very specific: line 29
Use WITH (CTEs) when the query has 3+ logical steps.
- Very specific: line 31
Use explicit JOIN ... ON ..., never implicit comma joins.
- Very specific: line 45
MUST NOT: write SELECT * in production-style queries.
- Very specific: line 47
MUST NOT: use deprecated syntax ((+) joins in Oracle, RIGHT OUTER JOIN style if LEFT OUTER JOIN would be clearer).
- Very specific: line 54
Questions about percentages or ratios: use AVG(condition::int) or COUNT(...) FILTER (WHERE ...) * 100.0 / COUNT(*).
- Very specific: line 55
Top-N queries: use LIMIT (or dialect equivalent), not ROWNUM or hand-rolled ranking, unless the user wants ties handled (then use RANK() or …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SQL from Question
Generate correct SQL from a natural-language question against a known schema.
Process
Confirm you have the schema. If not provided, ask for it. Accept any of:
- DDL (
CREATE TABLE ...) - Pasted output of
\d table_nameorDESCRIBE table_name - A list like "users (id, name, email, created_at), orders (id, user_id, total, ...)"
- Reference to a previously-shared schema in this conversation
If the schema is incomplete (e.g. user mentions "the customers table" but didn't share its columns), ask before guessing.
- DDL (
- Confirm the SQL dialect. Default to PostgreSQL. Ask only if the schema or question uses dialect-specific features and you're unsure (e.g.
LIMITvsTOP,CONCATvs||, window function syntax). - Restate the question in your own words before writing SQL. This catches misunderstandings before they become wrong queries. Example:
You're asking: "Of users who signed up in the last 30 days, how many placed at least one order with a total over $100?" Confirm or correct.
- Write the query. Follow these conventions:
- Use lowercase keywords (
select,from,where) for readability in this conversation; switch to UPPERCASE only if the user's existing code uses uppercase. - Always alias tables in joins with short, meaningful names (
users u,orders o). - Always qualify columns with table aliases when more than one table is involved.
- Use
WITH(CTEs) when the query has 3+ logical steps. Inline subqueries only for trivial cases. - Format multi-line. Never one-line a query with more than 2 clauses.
- Use explicit
JOIN ... ON ..., never implicit comma joins. - For aggregates, name every output column (
count(*) as user_count, not barecount(*)).
- Use lowercase keywords (
- Add a comment explaining intent at the top of complex queries. One sentence.
- Below the query, list assumptions you made. Examples:
- "Assumed
created_atis in UTC." - "Assumed soft-deleted users have
deleted_at IS NOT NULLand should be excluded." - "Assumed orders.status of 'completed' is the relevant filter."
- "Assumed
- Suggest one simple variation. Examples: "If you want this broken down by month, change X to Y." This catches the common follow-up before they ask.
What NOT to do
- MUST NOT write
SELECT *in production-style queries. List columns explicitly. Exception: ad-hoc exploration queries the user explicitly asked to keep loose. - MUST NOT invent column or table names. If the schema doesn't have what the question needs, say so.
- MUST NOT use deprecated syntax (
(+)joins in Oracle,RIGHT OUTER JOINstyle ifLEFT OUTER JOINwould be clearer). - MUST NOT silently change semantics. If the user asks for "active users" and "active" isn't defined in the schema, ask what defines active.
Edge cases
- Date/time questions without timezone info: assume UTC, state the assumption.
- Questions with "or" or "and" that could be parsed multiple ways: rephrase the question both ways and ask which is meant.
- Questions about percentages or ratios: use
AVG(condition::int)orCOUNT(...) FILTER (WHERE ...) * 100.0 / COUNT(*). Don't truncate integer division. - Top-N queries: use
LIMIT(or dialect equivalent), notROWNUMor hand-rolled ranking, unless the user wants ties handled (then useRANK()orDENSE_RANK()).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

