Skip to course content
Free SQL course

SQL for Data Analysis and AI

Module 12 Activity

Scenario

A colleague has prepared a table for an AI assistant to retrieve from and asks you to review it before it goes live. Everything you approve here becomes something the assistant can say to a user - and everything you miss becomes something it can say wrongly.

Task

  1. Build the retrieval table: one row per order, with a doc_id, self-contained content, and the

metadata needed to filter and cite.

  1. Check the grain. Confirm the number of rows in equals the number of rows out.
  2. Check that doc_id is unique, and that it is derived from a stable source key rather than a row number.
  3. Read the content of order 501 aloud. Could a reader tell what it describes with no other context?
  4. Find the rows whose customer has no recorded country, and check what the content string looks like for

them.

  1. Write the filter that would restrict retrieval to one country's orders, and state where that filter must

be enforced.

Deliverable

A review sign-off: five sample rows, the grain and uniqueness checks with their results, the defect you found in step 5 and its fix, and one sentence on permission enforcement.

Check your work

That names its own subject, so it survives being retrieved alone.

for . Status completed. - a sentence that reads as broken and tells the model nothing. Wrapping the column in COALESCE(c.country, 'unknown country') fixes it.

The sentence about permissions

Restricting retrieval belongs in the WHERE clause of the query that fetches candidate rows - never in an instruction asking the model to ignore what it has been shown. If a restricted row reaches the context window, treat it as disclosed, regardless of what the assistant then says about it.