/skardi:retrievalfrom skardi
Answers questions from live data served by a skardi-server (Postgres, MySQL, SQLite, MongoDB, files, GitHub, Slack) using the skardi CLI. Discovers sources, searches by meaning, then runs read-only SQL and reports the answer with the query.
Ships in skardi. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Your job: take a concrete question, find the data behind a running skardi-server that answers it, and come back with the answer plus the query that produced it. The loop is always the same: check whether it was asked before → discover → search meaning first → SQL for precision → check what came back → report. The first step applies whenever skardi-query-log is in your skill list; step 0 below.
The skardi CLI is a thin HTTP client — every command below is one request to the server, which holds the query engine, the source registrations, and the safety policy. You never need database drivers, connection strings, or credentials for the backing stores; if the server is reachable, you can work.
auto-context skill. This skill consumes whatever search surface already exists.SELECT. Writes (INSERT / UPDATE / DELETE, scheduled materialization) belong to Skardi's job path with its own review; do not do them from here even when a source would allow it.skardi CLI on PATH. One small binary, no runtime deps. Check with skardi --version. Install from the GitHub releases page — download the tarball for your platform, untar, put skardi on PATH.--server <URL> flag → $SKARDI_SERVER_URL → ~/.skardi/config.yaml → default http://127.0.0.1:8080. If auth is enabled on the server, pass --token or set $SKARDI_API_TOKEN.2 means the server was unreachable. That is an environment problem, not a query problem — see the stuck protocol.This skill runs on v0.5.0 or later of both CLI and server. The --purpose / --session-id audit pair and the --task that rides with it need v0.6.0 or later — the exception below. Deployment behavior — which sources exist, what is read-only, row caps — is discovered live and is never assumed from this text.
One exception:
--purpose,--session-idand--taskneed Skardi v0.6.0. The pair (skardi#232) and--task(skardi#255) are both in v0.6.0: itsskardi query --helplists all three flags, and its server records them in the audit ledger asai_context. v0.5.0 has none of them — the CLI has no such flags (git grep session-id v0.5.0 -- crates/cli/is empty) and the server has noai_contextat all (git grep ai_context v0.5.0 -- crates/server/is empty), so on a v0.5.0 server there is no ledger for them to land in. On v0.5.0, run the queries below without--purpose,--session-idand--task; everything else in this skill holds there.Probe the capability rather than trusting the version. A build of
maintaken between releases prints the previous release's number, soskardi --versionalone can mislead.skardi query --helplists--purposeexactly when the build carries the pair, and lists--taskexactly when it has that too; probe each separately. Each command template below shows, on commented lines, its form for a build without--taskand its v0.5.0 form. Where--taskis missing, drop it and send the pair alone; nothing else changes.
Before the first query, run this block. It does the capability check, mints
the one session id every query in this task will reuse (only when the audit pair
is available), and, when skardi-query-log is installed next to this skill and
the server is one you host yourself, asks its index whether this question has
been answered before:
if skardi query --help | grep -q -- '--purpose'; then
SKARDI_SESSION=$(uuidgen 2>/dev/null || echo "sess-$(date +%s)-$$")
fi
skardi query --help | grep -q -- '--task' && echo "this build takes --task"
ASK="<this skill's directory>/../skardi-query-log/scripts/ask.py"
# ask.py sends no API token, so it only serves a self-hosted server without auth.
# Skip it on Skardi Cloud (current context mode is cloud) and whenever a token is
# in play: in the environment, or saved with the current context in config.yaml.
CUR=$(skardi config get-contexts 2>/dev/null | awk '$1=="*"{print $2, $3}')
SAVED_TOKEN=$(skardi config view 2>/dev/null | awk -v cur="${CUR%% *}" '
/^[^ -]/ { top = $1 }
/^ *- name:/ { n = $0; sub(/^ *- name: */, "", n); gsub(/"/, "", n); mine = (n == cur); next }
/^ *token:/ && ((top == "contexts:" && mine) || top == "spec:") { print "yes"; exit }')
if [ -f "$ASK" ] && [ -z "$SKARDI_API_TOKEN" ] && [ -z "$SAVED_TOKEN" ] \
&& [ "${CUR#* }" != cloud ]; then
USE_QUERY_LOG=1
python3 "$ASK" "<the user's question, in plain words>"
fi
When the build takes --task, also settle the task line now, before the first
query: one line naming the larger piece of work this run of queries serves
(step 3 says what makes a good one). Write it down once and pass the exact
same string with --task on every query of the task, peeks included. Every
task gets one, even a single question: then the task line is that question.
Read what the last line printed before running anything else. If it lists a
question that is the same as this one, go straight to step 0 and reuse its SQL;
no skardi schema is needed. If it printed nothing (skardi-query-log is not
installed, or this is Skardi Cloud or a server that takes a token) or no
candidate matches, go on to discovery.
Which tables exist, which pipelines are registered, what a column means, what is writable — these are deployment facts. They differ per server and change under you. Re-discover them in every session rather than carrying them over from a previous conversation or from this file. The one thing that comes before discovery is step 0: a question already filed in the skardi-query-log index comes with SQL that ran against this server, and running it again is the check.
| Question | Command |
|---|---|
| Is the server up? | skardi health |
| Is source X reachable for pipeline Y? | skardi health <pipeline> |
| What data is there? | skardi schema |
| Which pipelines are registered? | skardi pipeline list |
| What does pipeline X take? | skardi pipeline show X |
Read what came back; do not check it against an expected shape. These
commands answer differently across deployments, and a route that exists on one
is absent on another — a hosted gateway may answer 404 with an empty body to
pipeline list, pipeline show and health <pipeline> while health and
schema work fine. That is not a broken server; it is a deployment without
that surface. Treat an empty or 404 answer as "this deployment does not offer
it" and take the documented fallback (step 2 goes straight to SQL), rather than
retrying or assuming the command is misused.
Two consequences worth stating, because instructions further down lean on them:
skardi schema may or may not carry operator-written descriptions. They
come from a semantics overlay the server was started with, and plenty of
deployments have none. Where they are absent, column meaning has to come from
a LIMIT 5 peek (step 3) and from asking, not from this file.skardi health <pipeline>, where it exists, has a known false negative: a
source registered at catalog level can report unhealthy — No table named '<source>' while queries against it work. Confirm with a real query before
believing a source is down.This step applies only when the opening block under Prerequisites set USE_QUERY_LOG: skardi-query-log is installed and the server is self-hosted with no token. Then the block already ran ask.py; act on what it printed before anything else in this flow. On Skardi Cloud, or any server that takes a token, skip this step and send every query, the final one included, with skardi query as steps 1 to 3 show: ask.py cannot authenticate there.
Its ask.py keeps an index of questions already answered and the SQL that
worked for each, plus pitfalls filed from earlier failures. Checking it takes
one command; skipping it means rediscovering the schema and rewriting a
statement a previous session already got right.
python3 <that skill's directory>/scripts/ask.py "<the user's question, in plain words>"
It needs a small config file the first time; skardi-query-log's SKILL.md says
what goes in it. Write it before running the command rather than skipping this
step.
ask.py "<question>" --sql "<SQL>" --session-id "$SKARDI_SESSION" --task "<task line>".
Then go to step 4.skardi query.ask.py … --sql command
instead of skardi query, so the next session finds it. Peeks and schema
discovery stay on skardi query.--session-id and --task keep the final query in the same session and task
as the peeks, exactly as skardi query would send them. Drop --task on a
build without it.Whether a listed question is the same question is your judgement; the script
only lists candidates. When skardi-query-log is not in your skill list, start at step 1.
Run skardi schema and read the answer it gives you. Each source arrives with a
name, a type, and a list of tables; each table arrives with a name and a column
list. Both the name shape and whether columns are enumerated vary by how the
source was registered, so take them from the response rather than from a
category in this file.
Use table names exactly as schema printed them. Some are bare
(orders), some are two- or three-part (shop.main.orders,
saas.github_repo.issues). Copy the string; do not reassemble it from parts
and do not add or strip qualification.
If a table came back with its columns, that is your schema — no further verification is needed or available.
If a table came back with an empty column list, the deployment does not
enumerate it. SHOW TABLES and information_schema are not available, and
DESCRIBE is refused on some deployments (HTTP 400 unsupported-statement),
so do not build a verification step on either. Peek instead:
skardi query --purpose "peek at orders to learn its columns" --session-id "$SKARDI_SESSION" \
--task "Q3 retention review" \
-e "SELECT * FROM shop.main.orders LIMIT 5" --table
# build without --task (probe: skardi query --help): drop that one flag:
# skardi query --purpose "peek at orders to learn its columns" --session-id "$SKARDI_SESSION" \
# -e "SELECT * FROM shop.main.orders LIMIT 5" --table
# v0.5.0 build (no --purpose/--session-id/--task): drop all three:
# skardi query -e "SELECT * FROM shop.main.orders LIMIT 5" --table
($SKARDI_SESSION is the task's session id and the --task value is the
task line; step 3 explains all three. Settle both before the first query,
peeks included.)
A successful peek both proves the name and shows the columns. If the peek fails, stop and ask for the table list rather than iterating guesses.
Extract two things before writing any real query:
query_execution_error (HTTP 500) or HTTP 400 planning-failed, and neither names the table. Treat any unexplained planning or execution failure as "check my table name first".LIMIT 5 peek plus asking is the only honest substitute — amount_cents meaning "divide by 100" is the kind of fact that silently corrupts an answer when skipped.If the question names data you cannot find, say so — do not query a lookalike table and present it as the answer.
Check skardi pipeline list for a search surface: the auto-context standard names (search-hybrid, search-vector, search-fulltext), or a pipeline the operator has declared to be one. Name-shape is how you find candidates; whether you may call one is decided by the declaration rule below.
If one exists (and clears the declaration rule below), run the user's question through it first, even when you expect to write SQL afterwards. It searches indexed content — documentation, policies, definitions, past decisions — and what comes back tells you what the terms in the question mean before you count anything. A question like "how many refunds under the new policy" needs the policy text (semantic surface) before the refund count (SQL) can be right:
skardi run search-fulltext -p 'query=refund policy' -p limit=5
# → "Refund policy changed on 2026-07-15: refunds are now allowed within 30 days …"
(search-hybrid takes more parameters — query, text_query, vector_weight, text_weight, limit. Check the signature with pipeline show: matching the standard shape makes a pipeline worth proposing; the declaration rule below still decides whether you may call it.)
If the search result alone answers the question (a "what does X say / find the doc about Y" question), stop there and cite the sources it returned.
Search hits inform your SQL; they never override the data. An indexed document can be stale or off-topic — use what it says to shape filters and interpret terms, but the registered tables are the system of record for numbers. If a document and the data disagree, report both, don't average them.
If no search surface exists, go straight to SQL. Do not build one — that is auto-context's job, offer it as a follow-up instead.
Which pipelines may you run at all? Default: none — a declaration is required. Pipeline SQL is validated when the server loads it, so a pipeline that would write to a read_only source cannot even register (the server refuses to start with it). But a write to a source the operator marked read_write is a perfectly legal pipeline — every auto-context deployment ships ingest / ingest-chunked, which insert rows — and pipeline show does not reveal the SQL, so nothing you can inspect at runtime proves a pipeline is read-only. Names and parameter shapes are labels, not proof: an INSERT pipeline named search-fulltext with query/limit parameters would pass every look-based test. Not writing is a hard promise of this skill, so looks never authorize a call. A pipeline is callable only when both hold:
skardi schema (e.g. an index table described as "served by the read-only search-fulltext pipeline"), or the user/operator confirms it in this session. Many deployments carry no descriptions at all — where schema returns none, the first form is simply unavailable and asking in this session is the only route; the absence authorizes nothing on its own. A description that merely mentions a pipeline's name declares nothing — what authorizes is the operator saying it does not write. Matching an auto-context standard signature — search-fulltext(query, limit), search-vector(query, limit), search-hybrid(query, text_query, vector_weight, text_weight, limit) — is a strong reason to propose one ("this looks like auto-context's standard search pipeline — confirm it's the unmodified read-only one and I'll use it"), but the declaration is what authorizes, not the match. Ask once per pipeline and keep the answer for the session.limit is not evidence the SQL applies it as a LIMIT, and a parameter named id is not evidence of a unique key — pipeline show cannot show you the SQL. The bound must be part of the accountable statement: "honors limit — returns at most that many rows", "unique-key lookup, at most one row", or "the unmodified auto-context standard pipeline" (whose shipped templates bound results by construction). With the bound declared, still pass limit explicitly and small (start at 5–20, raise deliberately) wherever the parameter exists, because skardi run output is not row-capped. A pipeline whose declaration is silent on the bound is not callable — get those rows through ad-hoc SQL with a LIMIT instead.Everything else — however retrieval-flavored its name — you do not call from this skill. Answer with an ad-hoc SELECT (validated read-only on every request) or ask what the pipeline is. Never run a pipeline to find out what it does.
This rule is a workaround for a gap the engine still has (v0.7.0 included), and is meant to go away. Asking a human to vouch for a pipeline is what you do when the machine cannot answer — and here it nearly can: the server already determines each pipeline's statement kind when it validates the SQL at load time (that is how a pipeline writing to a read_only source gets rejected at startup). It simply does not expose that verdict, so pipeline show returns parameters and nothing about what the statement does. Once the server reports statement kind — ideally alongside a result-bound signal — this whole declaration dance collapses into one runtime question the agent asks the engine, and the two conditions above should be deleted rather than maintained. That belongs to the runtime capability contract the engine still owes its callers; until it exists, declarations are the only honest way to keep the read-only promise.
Invocation: skardi run <name> -p key=value — values parse as JSON first (numbers, booleans), then fall back to plain strings.
On a build with the audit pair, the Prerequisites check has already minted one session id for this task. Reuse it for every query, including the peek:
skardi query --purpose "order counts by lifecycle state" --session-id "$SKARDI_SESSION" \
--task "Q3 retention review" \
-e "SELECT status, COUNT(*) AS n FROM shop.main.orders GROUP BY status" --table
# build without --task (probe: skardi query --help): drop that one flag:
# skardi query --purpose "order counts by lifecycle state" --session-id "$SKARDI_SESSION" \
# -e "SELECT status, COUNT(*) AS n FROM shop.main.orders GROUP BY status" --table
# v0.5.0 build (no --purpose/--session-id/--task): drop all three:
# skardi query -e "SELECT status, COUNT(*) AS n FROM shop.main.orders GROUP BY status" --table
skardi query carries --purpose and --session-id. They are sent as the ai_context: { purpose, session_id } object on the request, which is what the server's audit ledger records, the daily brief's intent breakdown groups by, and session-level learning aggregates on — a query without them lands as "(no declared intent)" with no session. The pair is all-or-nothing (the server rejects one without the other; the CLI enforces it too, since skardi#232, in v0.6.0 and later). --purpose is one plain-language line on why this query runs, ≤2000 characters; --session-id is any non-empty string ≤200 characters — one id per task, minted once (uuidgen) and reused across the task's queries so they group as one session. Purpose belongs in the flag, not in a SQL comment: a comment rides inside the SQL text where nothing aggregates it. (If SQL text does start with a comment, use the block form — a leading -- comment makes the CLI misparse -e "--..." as a flag.)skardi query also carries --task when the build takes it (the Prerequisites probe says whether it does). --purpose says why this query runs; --task names the larger piece of work the whole run of queries serves, like "September cross-repo delivery review" or "why checkout errors rose last week". It is sent as ai_context.task, which the daily brief reads to say what a day of queries was for: purposes alone summarize as a list of lookups, because the larger goal is written in no single row. Pick it once at the start of the task and repeat it verbatim on every query that serves the task, peeks included; a reworded task reads as a different piece of work. It only travels with the pair: the CLI refuses --task without --purpose. When the work really is one question, the task line is that question; send it anyway, so a build that takes --task records one on every query.read_write — but do not lean on that: retrieval work is read work, even on writable sources.Expected exactly one SQL statement). Run follow-ups as separate calls.SELECT * FROM <table> LIMIT 5 shows you actual value shapes — date formats, status spellings, NULL patterns — that schema output cannot. One peek prevents most wrong-filter answers.*, once you know the table. Every row you pull lands in your context and in the transcript. On a table holding personal or secret values (emails, phone numbers, tokens, message bodies), name the columns you are about to read before pulling them, and leave out the ones the answer does not use. The peek above is the one place * belongs, and on such a table peek at the shapes with a LIMIT 5 of the needed columns instead.COUNT, SUM, GROUP BY on the server beat pulling rows and counting them yourself — pulled rows are capped (next section) and the cap corrupts client-side aggregation silently.sqlite3 / psql / a driver. The server is the governed path — read-only enforcement, row caps, and the audit trail all live there, and an answer produced behind its back has none of them.Ad-hoc query results are capped at 1000 rows by default (--max-rows to change). When the cap bites, the CLI prints the rows it got to stdout and this note to stderr:
note: results truncated; pass a higher --max-rows to see the rest
--max-rows high enough to be provably complete.skardi run returns whatever the pipeline's SQL returns — control size through the pipeline's own parameters (limit and friends).GROUP BY total against a plain COUNT(*). Two queries that agree are evidence; one query is a draft.LIMIT 5 peek (status spelled paid vs PAID), then say "none found under these filters" — with the filters named.| Symptom | Meaning | Do |
|---|---|---|
| exit code 2 | server unreachable | Report it with the URL you tried. Do not retry in a loop; do not start a server yourself. |
| HTTP 400, refusal code, no detail | the statement hit policy. Codes seen in the wild: sql_validation_error, unsupported-statement (a write, DESCRIBE, SHOW), planning-failed (a name that did not resolve, multiple statements). The message names nothing — the code is all you get, and the same code covers several causes | Read the code, not a message. For unsupported-statement, rewrite as a single read-only SELECT; if the task genuinely needs a write, say it belongs to the job path and hand it back. For planning-failed, re-check the table name against what schema printed, then that the SQL is one statement. |
| HTTP 500, no detail | a wrong or under-qualified table name; also non-DataFusion syntax | Re-check the name against step 1 by peeking at it, fix qualification, retry once. The precise cause is only in the server logs, which the operator has and you may not. |
| HTTP 403 | authorization did not resolve — not the same as being denied. Message is generic by design (the resource stays in the operator's log so a listing cannot be used to enumerate hidden sources) | Retry; a transient one clears. If it persists while other callers succeed, report it and ask the operator for the log line — you cannot tell from the response which of several causes it was. |
| pipeline parameter errors | wrong names or types | Re-read skardi pipeline show <name>, match names exactly. |
| the same question failed 3 times | you are guessing | Stop. Show the user what you tried, what came back, and your best hypothesis of what is missing (a source not registered? a semantics overlay that would explain columns? a search surface that does not exist?). |
An honest "here is what I tried and where it stopped" beats a fourth guess.
Lead with the answer, then attach the evidence so the result can be re-run and audited:
410 orders are paid, totalling ¥507,467.60.
— from shop.main.orders via skardi query
build with --task: --purpose "paid order count and revenue" --session-id 3fa4… --task "Q3 retention review"
build with the pair only: --purpose "paid order count and revenue" --session-id 3fa4…
v0.5.0 build: /* purpose: paid order count and revenue */ (readability only; no ledger intent)
SELECT COUNT(*) AS n, SUM(amount_cents)/100.0 AS total_yuan
FROM shop.main.orders WHERE status = 'paid'
1 row, not truncated; cross-checked against GROUP BY status over all 1500 orders
State which source and table the answer came from, the exact query or pipeline + parameters, and the truncation status. If the semantic surface contributed context, cite what it returned too. If anything about the answer is approximate — sampled peek, capped rows, ambiguous column meaning — say so in the same breath as the number, not as a footnote.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
PostgreSQL, MySQL, SQLite, MongoDB, SQL
skardi, data-retrieval, sql-query, data-discovery, read-only
Other plugins' skills for the same job
7 skills in this plugin
/auto-contextTurn a folder of documents, a table you already have, or documents still inside a service (a wiki, cloud docs, a mailbox) into searchable context an agent can query: hybrid vector + full-text search served over HTTP by skardi-server. The index lives in a local SQLite file the skill creates, or in a database the user already runs (PostgreSQL+pgvector, MongoDB or Lance), where the skill never creates schema itself. Use when the user wants to build a knowledge base, index a corpus or a table for search, set up RAG or hybrid search, expose search as a REST endpoint, share retrieval across agents, or make wiki, Feishu, Notion or Confluence content searchable. Trigger on: build a RAG system, index my docs, index this table, make this folder searchable, search API over my postgres, production RAG on our existing DB. Requires a skardi-server built with --features rag (the skardi-server-full:0.7.0 image or a v0.7.0 source build)./document-cacheCache the local documents you read in the user's personal Skardi workspace, so that when the user refers to the same file again you read only the sections you need. Use before reading a local PDF, DOCX, XLSX or PPTX of any real size, and when the user refers back to a document ("the doc I showed you earlier", "that spec again", "the contract from last week"). Markdown and text files count only when the user calls them documents; not for a README, CHANGELOG or other file read during ordinary coding work. Never uploads without a consent recorded for that folder or given this turn, never uploads a file git ignores, and falls back to the local file whenever anything fails. Needs the Skardi MCP tools (find_cached_document, prepare_document_upload, read_document); without them it steps aside. Does not query the cache with SQL or build indexes.npx claudepluginhub skardilabs/skardi-skills --plugin skardi