npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@deepagents/text2sql

v0.6.0

Published

AI-powered natural language to SQL. Ask questions in plain English, get executable queries.

Readme

@deepagents/text2sql

AI-powered natural language to SQL. Ask questions in plain English, get executable queries.

Features

  • Natural Language to SQL - Convert questions to validated, executable queries
  • Multi-Database Support - PostgreSQL, SQLite, and SQL Server adapters
  • Schema-Aware - Automatic introspection of tables, relationships, indexes, and constraints
  • Domain Knowledge - Teach business terms, guardrails, and query patterns via teachables
  • Conversational - Multi-turn conversations with history and user memory
  • Explainable - Convert SQL back to plain English explanations
  • Safe by Default - Read-only queries, validation, and configurable guardrails

Installation

npm install @deepagents/text2sql

Requires Node.js LTS (20+).

Quick Start

import pg from 'pg';

import { InMemoryHistory, Text2Sql } from '@deepagents/text2sql';
import {
  Postgres,
  constraints,
  indexes,
  info,
  lowCardinality,
  tables,
  views,
} from '@deepagents/text2sql/postgres';

const pool = new pg.Pool({
  connectionString: process.env.DATABASE_URL,
});

const text2sql = new Text2Sql({
  version: 'v1',
  adapter: new Postgres({
    execute: async (sql) => {
      const result = await pool.query(sql);
      return result.rows;
    },
    grounding: [
      tables(),
      views(),
      info(),
      indexes(),
      constraints(),
      lowCardinality(),
    ],
  }),
  history: new InMemoryHistory(),
});

// Generate SQL
const sql = await text2sql.toSql('Show me the top 10 customers by revenue');
console.log(sql);

AI Model Providers

Text2SQL works with any model provider supported by the Vercel AI SDK, including OpenAI, Anthropic, Google, Groq, and more.

Teachables

Inject domain knowledge to improve query accuracy:

import {
  example,
  guardrail,
  hint,
  term,
} from '@deepagents/text2sql/instructions';

text2sql.instruct(
  term('MRR', 'monthly recurring revenue'),
  hint('Always exclude test accounts with email ending in @test.com'),
  guardrail({
    rule: 'Never expose individual salaries',
    reason: 'Confidential HR data',
    action: 'Aggregate by department instead',
  }),
  example({
    question: 'show me churned customers',
    answer: `SELECT * FROM customers WHERE status = 'churned' ORDER BY churned_at DESC`,
  }),
);

10 teachable types available: term, hint, guardrail, example, explain, clarification, workflow, quirk, styleGuide, analogy.

Grounding

Control what schema metadata the AI receives:

| Function | Description | | ------------------ | ---------------------------------------------- | | tables() | Tables, columns, and primary keys | | views() | Database views | | info() | Database version and info | | indexes() | Index information for performance hints | | constraints() | Foreign keys and other constraints | | rowCount() | Table sizes (tiny, small, medium, large, huge) | | columnStats() | Min/max/null distribution for columns | | lowCardinality() | Enum-like columns with distinct values |

Conversations

Build multi-turn conversations with context:

const chatId = 'chat-123';
const userId = 'user-456';

const stream = await text2sql.chat(
  [{ role: 'user', content: 'Show me orders from last month' }],
  { chatId, userId },
);

for await (const chunk of stream) {
  // handle streaming response
}

// Continue the conversation with the same chatId
const followUp = await text2sql.chat(
  [{ role: 'user', content: 'Now filter to only completed ones' }],
  { chatId, userId },
);

Explain Queries

Convert SQL to plain English:

const explanation = await text2sql.explain(`
  SELECT department, AVG(salary)
  FROM employees
  GROUP BY department
`);
// "This query calculates the average salary for each department..."

Documentation

Full documentation available at januarylabs.github.io/deepagents:

Repository

github.com/JanuaryLabs/deepagents