Skip to main content

Generate rules with AI

Goal​

You'll have an LLM propose data-quality rules for an asset from its profile statistics and save the good ones as rules on that asset — without typing the expectation kwargs by hand.

Status: shipped (Phase 2, native) — the in-app flow below is server-side and works out of the box under native AI (no provider to configure). It's a new capability under a new suggestion kind (rule_suggestions), not a re-opening of the one-shot flow retired in #133. The MCP-driven path is still available.

Prereqs​

  • The asset has been profiled at least once — rule suggestions are grounded in the profile's column statistics, so there's nothing to reason from without one.
  • Native AI in effect, or a BYOLLM provider configured (Settings → AI). Suggestions spend the org's LLM budget.
  • Workspace editor role or higher (can_create_rule) — viewers can view rules but can't generate or save them.

Steps (in-app)​

  1. Open the asset (Data Assets → click its row) and scroll to its Rules card. The ✨ Suggested lane sits at the top of the card.

  2. Get proposals.

    • For an asset with no rules yet, the lane generates a batch automatically — no click needed.
    • For an asset that already has rules, click Generate rules with AI. A dialog lets you optionally steer the run: type guidance ("focus on null / uniqueness checks on id columns; add a regex for security_id") and/or pick a severity emphasis. Leave both blank to generate as the automatic run would. Submit to generate.
  3. Review each proposal. Every row shows the rule type, its target, the model's confidence, and an editable severity. Nothing is written yet — proposals are validated against the expectation gallery server-side (invalid ones are dropped), but you decide what lands. If the model didn't rate a proposal, its severity reads Unrated (outlined): it is never defaulted to Critical behind your back. Pick a severity for it before you add it.

  4. Add the ones you want.

    • Add on a row drops that proposal into the rule table as an editable draft. It stays disabled ("Pick a severity first") while the row is unrated.
    • Accept all adds every surviving proposal at once. It waits until every surviving proposal has a severity.
    • Tweak a drafted rule inline, then click Save on its line to persist it (each new/edited row carries its own Save; deleting a rule persists on its own).
  5. Run the asset's rules (the ▶ in the asset header) to check the new rules against your data straight away. Refine or remove any that fail on the first run — the model doesn't know your data beyond the statistics it was given.

Alternative: drive it from your own MCP-connected LLM​

Instead of the server-side flow, you can author rules from your own MCP client — this spends your LLM budget (not the org's) and lets you iterate conversationally:

  1. Connect your MCP client to the hosted MCP server — see Connect an MCP client and the MCP server concept page for the tool inventory. You'll need a personal API key (dqk_) from Settings → API keys.

  2. Pull the asset's profile into the model with the rule-suggestion context tool — it returns the asset's column list, types, null rates, and sample statistics without generating anything yet.

  3. Ask the model to draft rules in plain language ("propose validation rules for this table; flag columns that should never be null and numeric ranges that look bounded"), refining conversationally before writing anything.

  4. Write the rules back by adding them to the asset's rules through the rules API or tool, then run the asset's rules to check them.

Reviewing suggestions that already exist​

The legacy Suggestions page (/suggestions, no longer in the navigation) still lists AI suggestions the platform has produced — today that's the custom-SQL rules from the natural-language → SQL flow, plus any legacy rows from before #133. Each eligible row has accept / dismiss controls; accept adds the rule to the chosen data asset (by default the suggestion's own asset), where it joins the asset's default validation, and sets the suggestion's review_status = accepted. Dismiss asks for an optional reason and sets review_status = rejected.

Bulk accept / dismiss (FEATURE-39)​

When several suggestions are waiting, the Suggestions list shows a checkbox on each eligible row (status completed, not yet reviewed) and a Select all on this page checkbox in the toolbar. Once one or more rows are selected:

  • Accept N selected — pick the target data asset once; the selected suggestions' rules are added to it in a single call. Already-reviewed rows are skipped and reported back in the summary. Per-row failures (missing suggestion, incompatible kind, target in another workspace) are reported individually — they don't block the rest of the batch.
  • Dismiss N selected — optional reason textarea, then confirm. Every selected row's review_status flips to rejected and the reason lands on each row's review_notes.

Both bulk endpoints require a recent password proof (step-up auth) — same bar as the single-row accept. Each affected suggestion produces its own audit_events row.

Cost control​

Rules you generate through your own MCP client spend your LLM budget, not the org's. The custom-SQL generation endpoint and the explanation endpoints still spend the org's configured provider budget (tracked in HARDEN-25 when it lands).