Natural Language To QSQL

Generating Complex Financial qSQL from Natural Language with the MCP qSQL Suggester

Author

Michaela Woods

Developer Advocate

Key Takeaways

  1. The MCP qSQL Suggester converts natural-language financial analytics requests into qSQL using a domain-specialized model.
  2. Its Claude Code skills can quickly return a consensus draft or validate the query against a reference result in q.
  3. The article demonstrates the workflow with five-minute OHLCV bars, running VWAP and functional-select queries.
  4. The specialist model passed 46 of 70 human-verified tasks, while the complete pipeline passed 690 of 1,078 machine-verified tasks.
  5. The GitHub release supports self-hosting on a single 24GB GPU, giving organizations greater control over sensitive query logic.
AI coding assistants have transformed how developers work with widely used languages such as Python and SQL, helping them, write, explain, and refine code. Achieving the same productivity gains has been harder for q developers. General-purpose models have seen far less q than Python or SQL, and q’s terse, symbol-dense syntax leaves little room for error: a single character can change what a query means. They can struggle with specialized financial queries as a result.
The MCP (Model Context Protocol) qSQL Suggester is our response. It turns natural-language requests into qSQL using a domain-specialized model. The goal is to help q developers move faster while enabling finance professionals who understand the question they want to ask but have limited experience with q or kdb+ to turn that domain expertise into queries and results.
The MCP qSQL Suggester combines a fine-tuned open-weight model, an MCP server and Claude Code skills. It’s part of KX’s wider work to bring natural-language interaction into the developer experience from querying data to building dashboards and writing code.

What the Suggester Returns for Financial Requests

The workflow begins with a developer describing the result they need in natural language. The suggester comes with two Claude Code skills. /qsql-coder-quick returns the draft along with how many of the independent candidates agreed on it (for example, 4 of 4). It stops there: it does not check the draft against a reference query. /qsql-coder goes one step further when the request calls for it: it also runs the draft in q next to a reference query and compares the results. You do not have to name either one. Describe the query you want and Claude routes to one of them on its own whenever the request looks like finance qSQL.

5-Minute OHLCV Bars

Turning tick data into bars is a staple of market data work. Here’s the request, with the table and result columns and what came back in Claude Code:

Claude Code output for a five-minute OHLCV bars request, showing four of four qSQL candidates agreeing on the generated query.
Claude Code output for a five-minute OHLCV bars request, showing four of four qSQL candidates agreeing on the generated query.

This request spelled out the table and the result columns, so the qsql-coder skill had nothing to ask for. Its “Instruction interpreted as” line restates the task before showing any code, which gives you a chance to catch a misreading. It read “bucket start” as the start of each 5-minute window, returned as a timestamp. The query is a single select that groups by symbol and by 0D00:05 xbar time. All four candidates agreed in the first round, and the skill saw no reason to run a reference check.

Running VWAP

Here’s another typical task for a trading desk: a running VWAP for each symbol, updated row by row.

Claude Code output for a running VWAP request, including execution against a reference query and a successful match.
Claude Code output for a running VWAP request, including execution against a reference query and a successful match.

The model used sums to keep a running total, and grouping by sym restarts it for each symbol while leaving the rows in their original order. Dividing the running notional by the running volume gives the VWAP so far.

This request included the formula, so the skill had something to check against. It ran the draft in q next to a reference query that Claude wrote from the same formula, and the two matched on a 1,000-row table. That confirms the query does what the instruction says. It doesn’t confirm the instruction says what you meant, so a spot check on your own data is still worth doing.

Functional Select with the Column as an Argument

Functional select is one of the more demanding parts of q. We asked for a function that takes a table and a column name and returns the average of that column per symbol.

Quick-mode Claude Code output for a functional select request, showing eight of sixteen candidates agreeing after three rounds.
Quick-mode Claude Code output for a functional select request, showing eight of sixteen candidates agreeing after three rounds.

The candidates split. Only 8 of 16 agreed, after three rounds, and the skill said so, noted that quick mode hadn’t verified the draft, and offered to run the full check.

ull-check Claude Code output for the functional select request, showing four of four candidates agreeing and successful reference validation.
Full-check Claude Code output for the functional select request, showing four of four candidates agreeing and successful reference validation.

This was a fresh run, so it drew new candidates, and this time all four agreed in the first round. The skill checked the draft in q against a static select on the same table. The results matched for price, and calling the function with size matched too, which confirms the column is chosen at call time. The skill reported that the code was functionally the same as the quick draft apart from the function name, so the earlier split didn’t signal a wrong answer.

Model output can vary between runs, so you may receive a different query when trying these prompts yourself. Treat every result as a draft: agreement between candidates shows that they behave consistently, not that they have correctly interpreted your intent. The model is specialized for qSQL so continue to use your general-purpose coding assistant for other q development tasks.

Quality comparable to leading models

Frontier models handle simple requests well. In our informal tests, they returned the same answers as the MCP qSQL Suggester on tasks like OHLCV bars and VWAP, which are typical of the examples above.

We evaluated the underlying specialist model on 70 human-verified qSQL tasks. Each model received one try per task, without tools or an opportunity to check its work. The specialist model passed 46 tasks, compared with 42 for Claude Fable 5, 37 for Opus 5.5, 34 for Sonnet 5.5 and 31 for Haiku 5.5.

Benchmark graphic comparing the specialist qSQL model with Claude models on human-verified and larger machine-verified task sets.
Benchmark graphic comparing the specialist qSQL model with Claude models on human-verified and larger machine-verified task sets.

A set that small cannot separate models a few tasks apart, so we also ran a larger, machine-verified set of 1,078 tasks drawn from the same distribution as the training data. There the model passed 595 on a single attempt, against 502 for Haiku 5.5, and 690 once self-consistency voting and the parse, qlint and execution gates were added. The larger set was written by an LLM and drawn from the same distribution as the training data, so we use it mainly to show what the pipeline adds over a single attempt, not to rank models.

Benchmarks are also a snapshot. Both frontier models and the MCP qSQL Suggester will continue to evolve, so the model card contains the latest results and evaluation methodology.

Privacy, control and token economics

Prompts can contain table schemas, business terminology and sensitive query logic. The specialist qSQL model can be hosted inside an organization’s environment, so requests sent to that model do not need to pass through an external inference endpoint. The assistant you drive it from, such as Claude Code, still receives your requests. For a setup that stays fully inside your network, the repository includes a query script that calls the server directly.

Compute and operational costs still apply, but self-hosting replaces per-token API billing with infrastructure costs the organization can manage directly.

Try the MCP qSQL Suggester

The MCP qSQL Suggester is available on GitHub. The repository contains the MCP server, Claude Code skills and instructions for connecting an MCP client to a self-hosted deployment.

There is no public endpoint in this release. To try it, you will need to host the model and server within your own environment, provide the required q/kdb+ components and connect your client using the supplied configuration. The model fits on a single 24GB GPU (e.g. Nvidia L4), and the server needs q/kdb+ with a licence. Please see the recommended prerequisites for more guidance. The model weights are available separately from the model card.

This is an evolving project, and testing against real financial queries will help us improve it. Explore the repository and let us know any feedback at incubation@kx.com.

AIによるイノベーションを加速する、KXのデモをお客様に合わせてご提供します。

当社のチームが以下の実現をサポートします:

  • ストリーミング、リアルタイム、および過去データに最適化された設計
  • エンタープライズ向けのスケーラビリティ、耐障害性、統合性、そして高度な分析機能
  • 幅広い開発言語との統合に対応する充実したツール群

専門担当者によるデモをリクエスト

「*」は必須フィールドを示します

ステップ 1 の 2

このフィールドは入力チェック用です。変更しないでください。


// social // social