Skip to main content
SQLOZ
Chapter 14 OzSuite™ AI & Advanced Tools

Chapter 14: OzAI - Natural Language SQL Assistant

Info: This chapter explains generating SQL from natural language with OzAI, improving slow queries, setting up a local AI provider and data-privacy principles.

In this chapter:

14.1 Overview

OzAI targets three common problems in database administration:

  1. The burden of writing complex SQL: In large table and relation networks, writing JOIN, GROUP BY and date functions correctly by hand takes time.
  2. Slow-query optimization difficulty: Manually analyzing missing indexes, Full Table Scan steps and inefficient subqueries in long-running queries is tedious.
  3. Enterprise data privacy: When external AI tools are used, there is a risk that database passwords and confidential customer data leak to external servers.

OzAI addresses these problems with a local-first provider model, credential redaction, and explicit endpoint validation.

14.2 Generating SQL from Natural Language

Follow these steps to generate complex queries without writing code.

  1. Press Cmd + K in the SQL editor, or click the OzAI icon on the editor toolbar.
  2. The OzAI Query Bar opens at the top of the editor.
  3. Type your request in natural language, for example:

    “Get the names, emails and total spend of customers who registered in the last 30 days and have at least 3 orders.”

  4. Press Enter or click Generate Query.

What happens in the background:

  • Schema sensing: OzAI collects schema context from the active database before generating SQL. The current window bounds this context to the first 25 tables; verify the generated statement against the full schema before running it.
  • Your request is passed to the AI model together with the schema as context.
  • The result is valid SQL that joins real tables such as users, orders and payments with correct column names.
  • Use Open in New Query to place the generated SQL in a query tab, then review it before running it.

14.3 Slow-Query Improvement & Index Suggestions

  1. Select or otherwise make the query active in the SQL editor.
  2. Open the OzAI window and press Optimize. The button is enabled when an active SQL statement is available.
  3. OzAI analyzes the query and the bounded schema context, then provides an Optimization Report:
    • Rewritten SQL: An optimized copy that converts subqueries to JOINs and selects only the needed columns instead of SELECT *.
    • Missing-index script: A ready command that speeds up the query, e.g. CREATE INDEX idx_orders_user ON orders (user_id, created_at);
    • Why it is slow: A clear technical explanation of why the query runs slowly.

14.4 Local AI Provider Setup

OzAI supports fully local AI engines to prevent data from leaving your device.

  1. Open SQLOZ → Preferences (Cmd + ,).
  2. Go to the OzAI Settings tab.
  3. Choose the local engine from the AI Provider menu:
    • Ollama (local): E.g. Llama, CodeLlama, DeepSeek-Coder, Mistral (default http://localhost:11434).
    • LM Studio (local): E.g. Qwen 2.5, DeepSeek R1 (default http://localhost:1234/v1).
  4. Fetch the active models installed on your machine with Fetch Live Models.
  5. Save with Test Connection & Save.

14.5 Security, Privacy & Data Protection

Enterprise security standards are active by default in the OzAI architecture.

  • No automatic row scan: OzAI builds prompts from the user request and the active schema context; query result rows are not automatically included.
  • Credential redaction: Connection URLs, passwords, tokens, API keys, and bearer values are redacted before the request is sent. Do not place confidential business data in the user prompt.
  • Local by default: Ollama and LM Studio/custom local endpoints use loopback HTTP defaults. A non-loopback endpoint must use HTTPS and explicit consent; credentials embedded in an endpoint URL are rejected.

Important: Schema names and the redacted user prompt are still data. Keep the endpoint local when policy requires that metadata to stay on the device. A remote endpoint is accepted only after explicit HTTPS consent.

OzAI - natural language SQL assistant