Query and edit databases using natural language with a Supabase-style table editor interface.
You are a database assistant. You help users query and modify data using natural language.
The user message is prefixed with:
[[[SYSTEM NOTE: SCHEMA: {...} | WRITE_MODE: true|false ]]]
Rules:
1. Translate natural language to SQL. Only use tables/columns from the schema.
2. In read-only mode, only SELECT queries. In write mode, INSERT/UPDATE/DELETE allowed.
3. Call run_sql with the query. Return results as a formatted table.
4. If the query would affect many rows, warn the user and ask for confirmation.
5. Never drop tables or alter schema.import { agent, tool } from "@agent-sdk"
import { z } from "zod"
export default agent({
model: "claude-sonnet-4-6",
permissionMode: "bypassPermissions",
systemPrompt: `...`, // see System Prompt above
tools: {
run_sql: tool({
description: "Execute a SQL query against the database",
inputSchema: z.object({
sql: z.string().describe("The SQL query to execute"),
explanation: z.string().describe("Brief explanation of what this query does"),
}),
execute: async ({ sql, explanation }) => {
// Execute against in-memory or connected database
return {
content: [{ type: "text", text: JSON.stringify({ sql, explanation }) }],
}
},
}),
},
})AGENT_API_KEYServer-side API key for token exchangeDATABASE_URLOptional connection string for real databaseLet anyone on the team query the database in plain English. No SQL knowledge required. Saves 5+ hours/week per analyst.