Ask Your Delphi Grid a Question in Plain English

· Components
Ask Your Delphi Grid a Question in Plain English

Your users do not want a filter row. They want to type amount greater than 500 sort by date desc and see the grid change. sgcWebSockets 2026.10 adds the AI Data Pack to sgcHTML: a query bar over the grid, the data table and the pivot, that turns a sentence into filters, sorts, a grouping, highlights and a limit.

The interesting part is not that it calls a model. It is what happens to the answer before it reaches your data.

Two Lines

uses
  sgcHTML_AI;

FAssistant := TsgcHTMLAIAssistant.Create(Self);
FAssistant.Provider := aiprOpenAI;
FAssistant.APIKey := ReadSetting('openai.key');

FGrid.AIAssistant := FAssistant;
FGrid.AIQueryEnabled := True;

That is the whole wiring. The bar appears over the grid, the question comes back as a chip that says what was understood, and a control clears it again.

It Works With No API Key at All

Leave the provider unset and the pack still answers. A rule based parser in the library understands the questions people actually type:

The same parser is the fallback when a provider call fails, and it is what runs on platforms without the AI units. So the feature degrades to something useful instead of to an error, and you can ship it to a customer who will not pay for tokens.

What Leaves the Machine

By default, your rows do not. The request carries the column names, their captions, their types and three sample values. Nothing else:

FAssistant.AllowRowDataToProvider := False;   { the default }
FAssistant.MaxRows := 50;                     { when it is True }

That matters for the obvious reason, and for a less obvious one: a smaller request is a cheaper and faster one.

Validation Is the Security Boundary

Whatever comes back is checked against your own columns before anything is applied. Every column name against the whitelist, every operator against a closed set, every value coerced by the type of its column, every limit clamped. If nothing survives, the whole set is cleared, explanation included, so no model text ever reaches the page.

The consequence is worth stating plainly: a question that tries to smuggle in instructions produces nothing. Not an error page, not a partial filter, nothing. We tested it with injection prompts and script payloads while building it, and that is the behaviour the QA suite now gates.

More Than the Query Bar

A column assistant. A grid column can ask for proposals, one per row, and every proposal is shown for a person to accept or reject. Nothing is written until a human says so.

Smart paste into a form. Paste an address, an email signature or a line out of a spreadsheet, and the form maps it onto its fields and marks what was filled.

An inline prompt. The new TsgcHTMLComponent_InlineAIPrompt is a small popover next to a field: ask, read the answer, accept or discard.

Which Provider

Seven, and it is one property: aiprOpenAI, aiprAnthropic, aiprGemini, aiprDeepSeek, aiprOllama, aiprGrok and aiprMistral. With aiprOllama and a BaseUrl, the whole thing runs on the customer's own hardware and nothing leaves the building.

Under it sits the other half of this release: TsgcAIChat can now ask any of those providers to answer JSON that follows a schema you supply, through the new ChatJSON method, which parses the answer and asks once more with the parse error attached if it could not be read. That is what makes a structured answer something you can act on rather than something you have to scrape.

See It on Real Data

The new demo 18.AIData serves four pages over about 26,000 seeded order lines, runs with no API key, and prints which engine answered each question and how many milliseconds the server took. The dataset is SQLite, created on first start, so there is nothing to install.

Upgrading

The pack is part of sgcHTML and is inert until an assistant is assigned: a grid with no AIAssistant renders exactly the markup it rendered before.

Watch It

There is a short video of this on the eSeGeCe channel.

Questions, feedback or migration help? Get in touch — you will get a reply from the people who wrote the code.