Skip to content

reasoningco/infer

Repository files navigation

Infer

Ask your database in plain English. Get back rows, charts, and answers.

TypeScript SDK that turns questions into safe, parameterized SQL — powered by LLMs, locked down by an 8-layer security pipeline.

Packages

Package Description
@reasoningco/infer Core engine — query planning, SQL compilation, security, connectors
@reasoningco/infer-react React hooks & components — QueryBar, AutoChart, ResultsTable
@reasoningco/infer-cli CLI — schema discovery, introspection, terminal querying

Quick Start

npm install @reasoningco/infer
import { Infer, PostgresConnector } from '@reasoningco/infer';

const infer = new Infer({
  connector: new PostgresConnector({
    connectionString: process.env.DATABASE_URL,
  }),
  llm: { provider: 'openrouter', apiKey: process.env.LLM_API_KEY },
  tenantId: 'tenant_123',
});

const result = await infer.ask('revenue by month last quarter');
console.log(result.rows);

await infer.close();

Security

Every query passes through 8 layers before touching your database:

Input validationLLM plannerPlan validatorEntity resolverSQL compilerSQL validatorSecure executorResult sanitizer

  • Function allowlist (not blocklist) — only 30 explicitly permitted SQL functions
  • Parameterized queries — zero string interpolation, all values via $1, $2, $3
  • Tenant isolation — tenant_id always injected server-side
  • Sensitive columns stripped from results automatically

React

npm install @reasoningco/infer-react @reasoningco/infer react
import { InferProvider, useInferQuery, AutoChart, ResultsTable, QueryBar } from '@reasoningco/infer-react';

function Dashboard() {
  const { status, result, handleSubmit, getInputProps } = useInferQuery();

  return (
    <div>
      <QueryBar onSubmit={handleSubmit} inputProps={getInputProps()} />
      {result && <AutoChart result={result} />}
      {result && <ResultsTable result={result} />}
    </div>
  );
}

Auto-chart detection picks the best visualization (line, bar, pie, scatter, metric card) based on column types and row count.

CLI

infer-cli introspect --connection postgresql://...
infer-cli generate-schema --connection postgresql://...
infer-cli ask "top 10 customers by revenue" --connection postgresql://...
infer-cli validate --schema ./infer-schema.yaml

LLM Providers

OpenRouter, OpenAI, Anthropic, and Ollama — all supported out of the box.

{ provider: 'openrouter', apiKey: '...' }
{ provider: 'openai', apiKey: '...', model: 'gpt-4o' }
{ provider: 'anthropic', apiKey: '...', model: 'claude-sonnet-4-20250514' }
{ provider: 'ollama', baseUrl: 'http://localhost:11434', model: 'llama3' }

Development

pnpm install
pnpm build
pnpm typecheck
pnpm test        # 160 tests across 15 files

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors