# Chat with Database

Introspects a database schema, converts questions to SQL, and runs read-only queries.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any URL or sending an `Accept: text/markdown` header. An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).



<DocsBaseSwitcher base="eve" agent="text-to-sql" />

<AgentPreview
  agent="text-to-sql"
  framework="eve"
  inputFields="[
  {
    name: &#x22;question&#x22;,
    label: &#x22;Question&#x22;,
    placeholder: &#x22;Show me the top 5 customers by revenue last quarter.&#x22;,
    type: &#x22;text&#x22;,
  },
]"
/>

## Summary [#summary]

The **Chat with Database Agent** answers questions about your data in plain
English. It introspects the schema, writes the SQL, runs it read-only, and
explains the results. Reach for it to give non-SQL users a safe way to query a
database, or to prototype analytics without hand-writing queries.

## Install [#install]

```bash
npx shadcn@latest add https://agentcn.vercel.app/r/eve/text-to-sql.json
```

## Composition [#composition]

```text
agent/
├── agent.ts                   # Agent definition (model + config)
├── instructions.md            # Introspect → SQL → execute instructions
├── lib/
│   └── db.ts                  # Database client (SQLite by default)
└── tools/
    ├── introspect_schema.ts   # Lists tables and columns
    └── run_query.ts           # Runs a read-only SELECT
```

## Customization [#customization]

* **Swap the database.** Replace the client in `lib/db.ts` with Postgres or MySQL.
* **Allow writes (carefully).** The `run_query` tool blocks non-`SELECT` SQL by
  default — relax that only behind explicit confirmation.
* **Add row limits.** Cap result size in `run_query` to protect against huge scans.
* **Swap the model.** Edit `agent/agent.ts`.
