Impact of AI Enrichment: Practical Examples

See how enriching your schema directly impacts LLM effectiveness through these examples.

Example 1: Healthcare Events-Tracking Schema

This example uses a schema designed to track healthcare events, focusing on doctor activity and the specific procedures performed during patient events.

The schema consists of the following three tables:

CREATE TABLE Practitioner (
    practitioner_id NUMBER PRIMARY KEY,
    nm VARCHAR2(80),
    speciality VARCHAR2(40),    -- This represents 'department'
    status VARCHAR2(20)         -- e.g., 'Active', 'Inactive'
);

CREATE TABLE Event (
    event_id NUMBER PRIMARY KEY,
    dt DATE,                    -- Date or time of the overall event
    practitioner_id NUMBER,
    location VARCHAR2(40)       -- e.g., 'OR1', 'ER', 'ICU'
);

CREATE TABLE EventDetail (
    event_id NUMBER,
    act_desc VARCHAR2(200),
    act_time TIMESTAMP,
    duration_minutes NUMBER,    -- Duration of this action or procedure
    CONSTRAINT FK_EVENT_ID FOREIGN KEY (event_id) REFERENCES Event(event_id)
);

Schema interpretation notes

Business query

Consider a hospital administrator asking the following question to an LLM:

"For each doctor, display their name, department, and the count of surgeries performed after 8 PM within the last six months."

Without AI enrichment

Without any annotations, the LLM must interpret the raw schema. This could lead to a flawed query like the one below:

SELECT
    PRAC.nm,
    PRAC.speciality,
    COUNT(EVT.event_id) AS surgery_count
FROM
    Practitioner PRAC
JOIN
    Event EVT
    ON PRAC.practitioner_id = EVT.practitioner_id
WHERE
    EVT.dt >= ADD_MONTHS(SYSDATE, -6)
    AND EXTRACT(HOUR FROM EVT.dt) >= 20
GROUP BY
    PRAC.nm,
    PRAC.speciality;

This query has several critical errors:

With AI enrichment

By applying the following annotations, you can provide the LLM with the necessary semantic context.

With this enriched context, the LLM can generate a far more accurate and reliable query:

SELECT
    PRAC.nm,
    PRAC.speciality,
    COUNT(*) AS surgery_count
FROM
    Practitioner PRAC
JOIN
    Event EVT
    ON PRAC.practitioner_id = EVT.practitioner_id
JOIN
    EventDetail ED
    ON EVT.event_id = ED.event_id
WHERE
    ED.act_desc = 'Surgery'
    AND ED.act_time >= ADD_MONTHS(SYSDATE, -6)
    AND EXTRACT(HOUR FROM ED.act_time) >= 20
GROUP BY
    PRAC.nm,
    PRAC.speciality;

Annotations markedly improve the query:

As this example illustrates, annotations bridge the gap between business terminology and the physical schema, guiding the LLM to understand data relationships and generate correct SQL.

Example 2: Human Resources Schema

For this example, we extend the HR sample schema by adding two new columns to the EMPLOYEES table: salary_conv and hire_dt.

Schema interpretation notes

In the EMPLOYEES table:

Business query

Consider a business analyst asking the following question to an LLM:

List each department and the average salary in USD of employees hired after 2020. Order the result by average salary, highest first.

Without AI enrichment

Without any annotations, the LLM can only read the raw table and column names in the schema. It may guess at names and joins, returning a flawed query:

SELECT
    d.department_name,
    AVG(e.salary) AS avg_salary
FROM
    EMPLOYEES e
JOIN
    DEPARTMENTS d
    ON e.manager_id = d.manager_id
WHERE
    e.hire_dt > DATE '2020-01-01'
GROUP BY
    d.department_name
ORDER BY
    avg_salary DESC;

This query has several issues:

With AI enrichment

By applying the following annotations, you can provide the LLM with the necessary semantic context.

With these annotations, the generated query is more accurate:

SELECT
    d.department_name,
    AVG(e.salary_conv) AS avg_salary_conv
FROM
    EMPLOYEES e
JOIN
    DEPARTMENTS d
    ON e.department_id = d.department_id
WHERE
    e.hire_date > DATE '2020-01-01'
GROUP BY
    d.department_name
ORDER BY
    avg_salary_conv DESC;

The improvements here are significant:

Key Takeaways

As illustrated in these examples, annotations enhance query accuracy by guiding the LLM to select correct join columns, apply appropriate units, use valid predicates, decipher object names, and more.

When you apply annotations consistently, you see a faster turnaround for data questions, fewer faulty joins, and a reduction in production defects from incorrect SQL. For an LLM, each annotation reduces the search space of possible query plans, allowing it to focus on the exact pattern you intended.

For organizations with strict compliance rules, annotations also allow administrators to control the exact contextual information shared with an LLM, which helps reduce the unintentional disclosure of sensitive data that may be present in free-form column comments.