agentleFS
alexeybanalexeyban/EKOS/.claude/skills/text-to-sql/SKILL.md

text-to-sql

Skill26 starsChanged 8 days agoMITView on GitHub

Write SQL (or a dbt model's SELECT) for a question about a database whose schema EKOS has compiled, using the ekos MCP tools to ground every table, column, join and value, and ekos_sql_check to catch mistakes before answering. Use whenever the user asks for a query, report SQL, a metric definition or a dbt model against tables in an EKOS project — "write SQL that…", "how many X per Y", "build a model for…" — even if they never say "EKOS".

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. nicholyx/ai-skills★ 6same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository4 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Learn the engine's rules: Call ekos_sql_check with only dialect (or none, for the project's): it returns that engine's rules — row limits …

    line 22
  2. Distinctive:

    Do not invent a column because the question uses a word for it — search, then ask if absent.

    line 67
  3. Distinctive:

    Do not trust an empty findings list as proof: the check is static and cannot see values or row counts.

    line 68
  4. Very specific:

    Do not run anything that writes.

    line 70

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Text-to-SQL over an EKOS project

EKOS compiles a database's DDL, comments and foreign keys into its ledger. Use the ledger as the schema: never guess a table, column, join or literal value you have not seen there or in the data. Measured on BIRD Mini-Dev (RFC 0241/0242), most wrong answers ran fine and looked plausible; the errors were in meaning — a value spelled differently in the data, rows repeated by a join, a sentinel 0 averaged in, integer division, NULLs sorted first. The procedure below targets exactly those.

Procedure

  1. Learn the engine's rules. Call ekos_sql_check with only dialect (or none, for the project's): it returns that engine's rules — row limits (FETCH FIRST on Oracle, TOP on SQL Server), integer division, quoting, case sensitivity, dates. Follow them while drafting.
  2. Find the tables. ekos_search with the question's nouns (2–3 keywords), or ekos_ekl FIND Object WHERE kind = 'Table' for a small schema. Read each candidate with ekos_state (its columns property holds names, types, keys and descriptions).
  3. Find the join path. Join only on foreign keys the ledger records (ekos_neighborhood on the table shows its ForeignKey edges). Joining two child tables on a shared parent key multiplies rows — aggregate each side first, or count DISTINCT.
  4. Check every literal. A value in the question ("Germany", "retail", "2017") must match the stored spelling and format. If a database is available, look: SELECT DISTINCT col … WHERE col LIKE '%Germany%' LIMIT 10. Text may be a list ('Artifact,Creature') → LIKE, or part of a longer value ('Berlin, Germany') → LIKE; dates are often text in a fixed format → compare in that format or with substr/strftime.
  5. Decide the grain. What is one row of each table, and what does the question count — entities, events, rows? Count DISTINCT entities when a join repeats them.
  6. Draft the SQL, returning exactly the columns asked, in the order asked.
  7. Run ekos_sql_check with the draft (and dialect if not the project's). Fix every error; read every warn and either fix it or say why it does not apply:
    • L001 unknown name → use the suggested real name.
    • L002 join off the foreign keys → use the path given, or justify the join.
    • L003 = on a list column → LIKE '%x%'.
    • L005 integer division → multiply the numerator by 1.0 (or cast it) for ratios and percentages.
    • L006 aggregate over a sentinel → filter the sentinel out.
    • L007 ascending ORDER BY … LIMIT on a nullable column → IS NOT NULL.
    • L008 date literal format → match the stored format.
    • L009 row-limit form, L010 ILIKE, L011 identifier quoting → the dialect's own form.
  8. Preview when you can. A person (not the MCP server) can run ekos sql check q.sql --database <name> (or --sqlite <file>): the same checks plus read-only probes on the live database — the result, value spellings, rows repeated by joins, ties. ekos sql generate "<question>" --database <name> runs this whole procedure as an agent. With any read-only connection: an empty result, a single NULL, or two rows tied at the top of an ORDER BY … LIMIT 1 all mean the query needs another look.
  9. Answer with the SQL, the tables and join path it uses, and any assumption you made about a value or definition the ledger does not state.

dbt models

The same steps apply to a model's SELECT. Reference upstream models and sources with {{ ref('…') }} / {{ source('…', '…') }} names that exist in the ledger (dbt models are Table objects recovered from the project). Check the SELECT with ekos_sql_check before templating it, with dialect set to the warehouse's (trino, postgres, snowflake, …).

What not to do

  • Do not invent a column because the question uses a word for it — search, then ask if absent.
  • Do not trust an empty findings list as proof: the check is static and cannot see values or row counts. Steps 3, 4 and 7 cover what it cannot.
  • Do not run anything that writes. EKOS's tools are read-only; so must your previews be.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.