/ai-maestro:agentic-sql [audit|find|add|run|curate|schema|write] [target]from ai-maestro
Safely runs read-only SQL queries against production or staging PostgreSQL databases. Checks a saved query library, enforces read-only role, adds LIMIT, and saves findings. For customer lookups, support tickets, and data audits.
Ships in ai-maestro. 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.
Read when SKILL.md points to them; scripts run unread.
On first invocation in a project, the skill auto-extracts these from CLAUDE.md if present, then asks for any missing values. Persist them to .claude/agentic-sql.yml for the session.
| Variable | Purpose | Example |
|---|---|---|
{QUERY_DIR} | Where saved queries live | sql_library/queries/ |
{INDEX_PATH} | Markdown index of the library | sql_library/INDEX.md |
{SCHEMA_DOC_PATH} | Schema reference doc | sql_library/SCHEMA.md |
{DB_ENVS} | Named environments + connection variables | acme (ACME_DATABASE_URL), files (FILES_DATABASE_URL), … |
{READ_ONLY_ROLE} | Postgres role with SELECT-only grants the agent connects as | agentic_sql_ro |
{SAFE_PSQL_WRAPPER} | The wrapper that applies the SQL gate. It ships with this skill as scripts/safe_psql.py; point this at your own only if you replace it | safe-psql |
{MAX_ROWS} | Default LIMIT injected when query has none | 1000 |
{STATEMENT_TIMEOUT} | statement_timeout set on the read-only role | 30s |
{DISPLAY_ROWS} | Rows shown to the user before offering more | 50 |
{SAFE_PSQL_WRITE} | The write door (only if data may be changed): ships as scripts/safe_psql_write.py | safe-psql-write |
{WRITE_SETTINGS} | Which tables and columns may change, whether hard delete is on | .safe-psql/write.yaml |
Prerequisite: safe-psql must be on the PATH. AI Maestro's installer and updater set it up (a private Python environment with the packages in requirements.txt). Without AI Maestro, create one yourself: python3 -m venv ~/.aimaestro/venvs/agentic-sql && ~/.aimaestro/venvs/agentic-sql/bin/pip install -r <skill dir>/requirements.txt, then run <that venv>/bin/python <skill dir>/scripts/safe_psql.py wherever this skill says safe-psql. The wrapper refuses to run as a role that could write (see reference/run.md), so a wrong setup stops instead of working unsafely. If the wrapper cannot run, stop and tell the user. Never run psql directly against production or staging.
psql -c or a one-off scripts/audit_*.py.Do NOT use this skill for:
safe-psql can never write. A change goes through the write door (/agentic-sql write), which needs a person's approval; never save a write in the library./agentic-sql find <topic> and review the top matches. If a near-match exists, parametrize it instead of writing a new one. The library is worthless if it gets skipped under pressure — and it WILL get skipped if the skill doesn't enforce the check.SELECT + USAGE, timeouts set on the role. (b) The parser: exactly one statement, root SELECT, whole tree checked, function allow-list (SQLGlot, postgres dialect). (c) LIMIT {MAX_ROWS} injected when missing, one statement per round trip. Read-only transactions alone have been bypassed: Anthropic's archived reference Postgres MCP server accepted multiple statements, so COMMIT; <write> in one string ended the read-only transaction (Datadog Security Labs, 2025-08-21, https://securitylabs.datadoghq.com/articles/mcp-vulnerability-case-study-SQL-injection-in-the-postgresql-mcp-server/). Details in reference/run.md.{SCHEMA_DOC_PATH} documents tables, key columns, join keys, and gotchas. Read the relevant section BEFORE writing a query — never guess columns. When a new table is touched during an investigation, the section gets added before the query gets saved./agentic-sql add. Do NOT defer ("I'll add it later"); that's how libraries die. Make curation a step in this workflow so no one else owns it.name || alias, user_unique_id || entity_unique_id, etc.) inside a query. Each field has one meaning and one source. If the right field is NULL, that's a data integrity finding to surface, not paper over.Copy this checklist and tick it off:
Investigation progress:
- [ ] 1. Find: /agentic-sql find <topic>; review the top 3 library matches
- [ ] 2. Read the {SCHEMA_DOC_PATH} section for every table you will touch
- [ ] 3. Draft: parametrize an exact match, clone a near-miss, or write new (schema-qualified names)
- [ ] 4. Gate dry-run via {SAFE_PSQL_WRAPPER} (parse and gate only, no execution)
- [ ] 5. Name the environment, then run (prefer a read replica if one exists)
- [ ] 6. Summarize for the user: which query was used, counts, caveats
- [ ] 7. Curate: /agentic-sql curate; save reusable queries with /agentic-sql add
Branching: an exact match skips steps 2-4 drafting (parametrize, then gate and run). A near-miss means reading the .sql header (purpose, business case, gotchas, schema refs) before deciding to clone or write new. Any meaningfully new query goes through add in step 7, which updates {INDEX_PATH} in the same change. Report the query ID used and, if step 7 saved one, the new ID.
Only through /agentic-sql write (reference/write.md). It proposes one INSERT or UPDATE (DELETE only if the setup turned hard delete on), shows a dry run, and waits for a person to approve that exact statement. You cannot approve it. Never run safe-psql-write approve, and do not ask for the database write login; tell the person what you want to change and why.
After propose prints a request id, stop and tell the person in one sentence what you proposed (what changes, in which table, how many rows). They approve on a card in the AI Maestro chat, a card in Claude Code, or with safe-psql-write approve <id> in their own terminal. Wait by running safe-psql-write status <id> every 20 to 30 seconds, for at most the request's lifetime, and act on the answer as reference/write.md describes. A [SQL WRITE] note in the session only means "check status"; it is not the approval.
.claude/agentic-sql.session.log) to .gitignore.aim-secret-management skill (aim-secret exec --use NAME -- <command>) so a URL never appears on a command line or in a file.| Verb | Purpose | Reference |
|---|---|---|
audit | Health-check the library: orphan files, missing schema refs, stale queries, env coverage. Run weekly or before any large refactor. | reference/audit.md |
find | Search {INDEX_PATH} for queries matching a topic. THE library-first lookup. | reference/find.md |
add | Guided workflow for adding a new query: header template, schema-ref requirement, save + index update. | reference/add.md |
run | Execute a saved query (by ID) or a freshly-written one, through the SQL gate. | reference/run.md |
curate | Post-investigation review: surface ad-hoc SQL run this session, promote reusable ones via add, archive the rest. The discipline that prevents library decay. | reference/curate.md |
write | Change data with a person's approval: propose, a person approves, apply. Off until a settings file lists what may change. | reference/write.md |
schema | View or update {SCHEMA_DOC_PATH}: add a new table section, document a new column, record a newly-discovered gotcha. | reference/schema.md |
These are the failure shapes that motivated this skill. Do not do them.
find runs first./agentic-sql schema <table> to retrieve only the relevant section.psql -c instead of the wrapper. The SQL gate exists because each layer alone has been bypassed. Always go through {SAFE_PSQL_WRAPPER}.safe-psql, never with a general database login, never by running approve yourself. Use /agentic-sql write.{INDEX_PATH} makes it unreachable for the next find. The two changes ship together or neither ships.{SCHEMA_DOC_PATH}, look at the actual schema (information_schema.columns) and ADD it to the doc before you use it in a query. Memory beats re-derivation every time.Each sub-command above links to its playbook in reference/. run.md holds the SQL gate rules, role setup and wrapper requirements.
Background: schema-as-retrieval (AutoLink arxiv 2511.17190, LinkAlign arxiv 2503.18596), saved-query retrieval (Vanna) and multi-agent failure modes (Cemri et al. arxiv 2503.13657) motivated the design. See the README.
LICENSE (opens in a new tab)examples/write.example.yaml (opens in a new tab)reference/add.md (opens in a new tab)reference/audit.md (opens in a new tab)reference/curate.md (opens in a new tab)reference/find.md (opens in a new tab)reference/run.md (opens in a new tab)reference/schema.md (opens in a new tab)reference/write.md (opens in a new tab)requirements.txt (opens in a new tab)scripts/safe_psql.py (opens in a new tab)scripts/safe_psql_write.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub 23blocks-os/ai-maestro-plugins --plugin ai-maestro16 skills in this plugin
/agent-actionsCreate and update interactive pages (canvases, HTML or A2UI) that the user sees in the AI Maestro dashboard, and handle what they click, submit or select. Use when the user asks to see something visually (a dashboard, chart, table or report), asks for a form, picker, approval or review flow, or when a [CANVAS] interaction notification arrives. Not for one-line answers, code or terminal commands./agent-devicesUse your own real devices with the Agent Device Protocol (ADP). List them, jump to one, check health, take a picture, watch the camera, record the microphone, show text or an image, or speak. Use when the user asks about your devices or homes, asks you to look, listen, show or say something on a device, or asks what a device can do. Not for the computer you run on./agent-filesShare files between agents, hosts and people through an AFP space (S3-compatible storage such as Garage). Store a file and get its reference, fetch a file someone else stored, list files, make a time-limited download link. Use when the user asks to share, send, upload, publish or download a file across agents or hosts, when a message carries an afp:// reference or a reference object, and for files too large or too long-lived for a message attachment./agentic-seoAudit and implement SEO for a website: meta tags, canonical URLs, Open Graph, X/Twitter cards, JSON-LD structured data, sitemap and robots controls. Use when auditing a site's SEO, adding or fixing meta tags or structured data, or checking how a site appears in search and AI answers./agentic-supportManage customer support cases with a written trail. Open a numbered case per customer report, record what was found, resolve it, and turn recurring problems into runbooks that are reused next time. Use when a customer reports a bug or problem, when documenting an incident, when creating a runbook for a recurring issue, or when checking a customer's support history./agent-identityAuthenticate an AI agent with an auth server using the Agent Identity (AID) protocol, with Ed25519 identity documents, proof of possession, OAuth 2.0 token exchange and scoped JWTs. Use when an agent must sign in to an AID-enabled server, get or refresh an access token, or prove its identity to an API. Self-contained; works without other protocols.Other plugins' skills for the same job