From natural-language questions to validated SQL: AskChokro

How AskChokro validates generated SQL, applies configured tenant policies and evaluates database questions.

AskChokro is an open-source TypeScript and Node.js engine for adding natural-language database questions to an application. Its public implementation turns a model's proposed SQL into a query that is checked against explicit policies before execution.

This case study follows the public source at the linked revision. It explains implementation decisions and documented regression cases; it does not report new customer outcomes or model benchmarks.

The problem: a plausible query can still be the wrong query

A developer connecting an AI model to a SQL database has more to decide than how to phrase a prompt. A generated query may contain multiple statements, refer to an excluded table, or omit a tenant constraint. The integrating application needs to decide which data is accessible and supply an authenticated identity.

AskChokro puts a validation and rewriting pipeline between generated SQL and database execution. These checks complement database permissions and application authorization.

Five decisions visible in the source

1. Validate the parsed statement before execution

The validator parses SQL into an abstract syntax tree (AST), rejects multiple statements and non-SELECT statements, and applies configured table and column policies. Parsing provides a representation of the query's structure for these checks. The agent pipeline runs validation before tenant rewriting, row limits and execution.

Source: SQL validator and agent pipeline.

2. Make tenant scoping an explicit policy

The tenant rewriter uses configured table lists and tenant columns. It adds predicates to the SQL tree and can place joined-table constraints in JOIN ON clauses, aiming to preserve LEFT JOIN behavior. The application supplies the authenticated tenant identity and policy; the library cannot determine those responsibilities on its own.

Source: tenant rewriter.

3. Translate dialect names at the parser boundary

A database adapter's name is not always the parser's expected name. The dialect mapping translates identifiers such as mssql to transactsql. Some adapters use a related parser dialect, so compatibility should be checked against the SQL subset an integration actually uses.

Source: dialect mapping.

4. Record model fallback during evaluation

The evaluation runner distinguishes transient provider failures from structural provider unavailability and records fallback use. A run that uses different providers should be described as such. Its outcome is not automatically a measurement of one model.

Source: evaluation runner.

5. Compare executed results and sample across categories

The evaluation tooling executes queries, compares database results, samples across dataset categories and produces reports. Dataset size and a configured CI threshold describe the evaluation setup. They do not establish that a run passed or that an application will behave reliably in production.

Source: evaluation runner and evaluation workflow.

Three regression cases worth understanding

Identifier case: the tenant tests document a case-sensitive comparison that could miss Users when the configured table was users. The reviewed implementation compares names without case sensitivity, and the regression test checks the resulting predicate.

Apostrophes in tenant values: the source documents literal serialization requiring explicit escaping. The rewriter doubles single quotes before building the AST literal, and a regression test checks the serialized output.

SQL Server dialect naming: passing an adapter name directly to the parser could fail. The mapping uses the parser's expected dialect identifier, with tests covering SQL Server syntax.

These are cases documented in the code and tests. They are not presented as customer incidents, and the test suite was not executed for this article.

Source: tenant regression tests and validator regression tests.

What this implementation does not establish

SQL validation and tenant rewriting are layers in an integration. Correct authentication, policy configuration, database privileges and query/resource limits remain application responsibilities. A supported adapter does not guarantee every vendor-specific SQL construct.

No new latency, accuracy, cost or security outcome is claimed here. To report measurements, record the source revision, dependencies, database fixture, provider/model, sampling settings, commands and generated reports. Reproduce the relevant test and evaluation runs before using their outcomes in a deployment decision.

Explore the project

AskChokro provides web adapters for Next.js, Express, Fastify and Hono. Start with the public setup documentation and review the policies required by your application.

Read the repository · View the npm package

Discuss an AskChokro integration with Digital Chokro

Prepared with AI assistance using the linked public implementation and regression tests.