Understand
The deterministic parser reads explicit instructions locally. It claims one only when it understands every word; anything else goes to your model.
Open source · MIT · TypeScript
Pragma turns plain language into a validated search, filter, sort and pagination query that any table, API or database can run. Explicit requests are answered in the browser in about a millisecond; your own model handles the rest.
Works with
How it works
Natural language is only the input. The source of truth is a typed query checked against your schema.
The deterministic parser reads explicit instructions locally. It claims one only when it understands every word; anything else goes to your model.
Every proposal is checked against your schema: fields, operators, value types, limits. Hidden fields are unreachable. Nothing is guessed.
Changes apply to the current query, so follow-ups just work. Chips and explanations come from the validated result, so they match what runs.
Features
Most instructions never leave the browser. The model is called only for phrasing the parser can't fully understand, and answers are cached.
Ambiguous requests get options that apply instantly, with no second model call.
Suggestions come from the schema, locally. Types and aliases included.
One small interface. Keys stay on your server, with retries, fallbacks and a circuit breaker built in.
Requests outside the schema get a reason and suggestions instead of an invented filter. Every warning and error has a stable code.
Error codes →Quick start
Describe your table once. Drop in the ask bar. Feed the query to your table or your API.
import { createEngine, defineSchema } from '@avinash-baraiya/pragma';
import { AskBar, PragmaProvider, QueryChips } from '@avinash-baraiya/pragma/react';
import '@avinash-baraiya/pragma/styles.css';
const schema = defineSchema({
schemaVersion: '1',
resource: 'customers',
fields: [
{ id: 'name', label: 'Name', type: 'string' },
{ id: 'country', label: 'Country', type: 'string' },
{ id: 'revenue', label: 'Revenue', type: 'number' },
{ id: 'createdAt', label: 'Signed up', type: 'datetime' },
],
});
const engine = createEngine({ schema });
export function App() {
return (
<PragmaProvider engine={engine}>
<AskBar />
<QueryChips />
<CustomersTable /> {/* reads usePragma().query */}
</PragmaProvider>
);
}// app/api/pragma/route.ts: only needed for free phrasing. Keys stay here.
import { createPragmaHandler } from '@avinash-baraiya/pragma/server';
import { gemini } from '@avinash-baraiya/pragma/providers/gemini';
export const POST = createPragmaHandler({
schemas: { customers: schema },
provider: gemini({ model: 'gemini-3.5-flash-lite', apiKey: process.env.GEMINI_API_KEY! }),
});{
"version": "1.0",
"resource": "customers",
"search": null,
"filter": {
"type": "group",
"logic": "and",
"children": [
{ "type": "condition", "field": "country", "operator": "eq", "value": "India" },
{
"type": "condition",
"field": "createdAt",
"operator": "last",
"value": { "amount": 30, "unit": "day" }
}
]
},
"sort": [{ "field": "revenue", "direction": "desc" }],
"pagination": { "type": "page", "page": 1, "pageSize": 20 }
}The playground runs the real engine on 500 sample customers, right in your browser.