Course contents · Lesson 15 of 24

Connect AI to Enterprise Data: APIs, Databases, Docs

Enterprise Integration and Trust · Lesson 15 of 24 · 10 min Engineer

In week 1 you asked Nimbus IT for data access (lesson 3). Now production has started, and IT sends a form per system: which data, why, what permission, how long? The live assistant needs enterprise data, the records and documents a company keeps in its own systems. This lesson covers where that data lives, the least access that works, keeping it fresh, and what the AI must never see.

The office park: many systems, many gates

Each Nimbus system is a building with its own data owner, the team that decides who may use its data, and its own gate: a database login, an API token (a secret string a program sends to prove who it is) or a folder permission. One owner's pass opens nothing next door.

The assistant holds its passes through a service account, an account for a program rather than a person, so every read is logged under its name and an owner can switch it off alone. Staff logins come later, in SSO and Access Control.

Lesson 2's request is back: check each draft against the policy, since handlers spend 20 minutes a claim checking cover (lesson 6). Meera signed it as a change request, adding three systems beyond the inbox:

  • Policy API: is the policy real, active on the date of loss, the claimant's, and for this claim type? A format check passes typos such as NA-448121.
  • Claims database: earlier claims on the policy, to flag duplicates or find the CL-55190 cited in lesson 10's claim 3.
  • Document store: the policy wording, the terms saying what is covered, so the draft can show the clause.
Architecture diagram, illustrative, titled every system has its own gate and pass. In the middle, the Nimbus assistant drafts each claim record and only reads. On the left, the shared claims inbox, owned by the IT email team, feeds it through a pass that reads one mailbox. On the right, three systems send data to it over read-only arrows, each with its own owner and pass: the claims database, owned by the claims system team, SELECT on one view; the policy API, owned by the policy system team, a token with the scope policies:read; the document store, owned by the product team, read on the wordings folder only. Below, the draft goes to the review page, where a handler checks and saves it, and only that save writes to the claims API, whose pass is create only. A pink dashed box lists data never fetched from any source: bank details, health declarations and other people's claims
Four owners, four passes that only read; the one write waits for a handler.

The aha: every pass only reads; the one write waits for a handler's save.

Where enterprise data lives: databases, APIs and documents

Enterprise data comes in three shapes, each with its own gate:

  • Databases hold rows and columns, read with SQL (SQL Basics). Ask for a read replica, a copy kept in sync for reading (Managed Databases), so the assistant can't slow the live system.
  • APIs are a system's front desk (What Is an API?): they enforce its rules, and their tokens often carry scopes, named permissions such as read-only.
  • Documents, such as policy wordings, sit in a document store; to search them by meaning, you index them, as RAG does.

Prefer the API where one exists, and never write straight into another system's database: that skips the application's checks. Hence two doors to the claims system: a replica view for reading, the API for creating records.

Read-only first: the least access that works

Least privilege means an account gets only the access its job needs (Cloud IAM Explained). It matters twice for an AI: model output can be wrong, and text in an email can steer it, lesson 12's prompt injection. What the account can't do, no bug or injected instruction can make it do.

So start read-only, with only the fields you need and an end date. Let code, not the model, write the queries, with the claim's values passed as parameters. Each pass follows one loop:

Flowchart of six steps from top to bottom. 1, write the request: what, why, which fields, for how long. 2, the data owner asks whether it is the least access that works: fewer fields, read-only, an end date. If too broad, narrow the request and ask again from step 1. If yes, 3, grant it on a test copy, with the assistant's own account and test data. 4, highlighted, test both ways: the needed data reads and everything else is refused. If a test fails, fix the grant with the owner and retest from step 3. If both pass, 5, the owner and security approve the same grant in production. 6, use it and review it: the password lives in a secrets store, and the pass has a review date. A note says step 4 is the easiest to skip: test the refusals too
Test the refusals, not just the reads, before anyone approves production.

The aha is step 4: a grant is half tested until you see it refuse the wrong data.

Test a read-only pass on your laptop

Try step 4 on a practice database, using Docker (What Is Docker?). The first command starts PostgreSQL, a widely used database server, pinned to version 18.7, with the password lab-only; the second opens psql, its command-line client, inside the container, where none is asked:

docker run --name nimbus-db -e POSTGRES_PASSWORD=lab-only -d postgres:18.7
docker exec -it nimbus-db psql -U postgres

Docker downloads the image once, then prints a long container ID. Then you should see the end of psql's welcome:

Type "help" for help.

postgres=#

If psql says connection to server on socket … failed, the server is still starting: wait a few seconds and retry. Cannot connect to the Docker daemon means Docker isn't running. Your own psql can't connect: no port is published.

Now play the claims system team. Paste a claims table with a bank_account column, one made-up row, a view (a saved query that looks like a table) without that column, and a role, PostgreSQL's name for a user, that may only read the view:

CREATE TABLE claims (
  claim_id      text PRIMARY KEY,
  policy_number text,
  date_of_loss  date,
  status        text,
  bank_account  text
);
INSERT INTO claims VALUES
  ('CL-55190', 'NA-519302', '2026-03-14', 'closed', '12345678');
CREATE VIEW claims_for_ai AS
  SELECT claim_id, policy_number, date_of_loss, status FROM claims;
CREATE ROLE nimbus_assistant LOGIN PASSWORD 'assistant-pw';
GRANT SELECT ON claims_for_ai TO nimbus_assistant;

psql answers each statement by name: CREATE TABLE, INSERT 0 1, CREATE VIEW, CREATE ROLE, GRANT. A view reads its table with its owner's rights by default, so the assistant needs none on claims. Test both ways; SET ROLE switches this session to the assistant's rights:

SET ROLE nimbus_assistant;
SELECT * FROM claims_for_ai WHERE claim_id = 'CL-55190';
SELECT bank_account FROM claims;
INSERT INTO claims (claim_id) VALUES ('CL-00001');
RESET ROLE;

You should see the row without bank details, then two refusals:

SET
 claim_id | policy_number | date_of_loss | status
----------+---------------+--------------+--------
 CL-55190 | NA-519302     | 2026-03-14   | closed
(1 row)

ERROR:  permission denied for table claims
ERROR:  permission denied for table claims
RESET

Both errors mean the test passed. If the bank_account query prints 12345678, you are still postgres, a superuser, which skips permission checks. In production, the assistant's password lives in a secrets store, a service that hands passwords only to approved programs. docker rm -f nimbus-db deletes the practice container.

Keeping data fresh and in sync

Data is fresh when it still matches its source. Give each source a freshness target, then choose how to read it:

  • Read live, per claim: the policy API: a policy cancelled this morning must show as cancelled now. If it is down, flag the draft unchecked, lesson 13's fallback.
  • Read a replica: the claims database. A replica can lag, often by seconds, so a claim saved a moment ago may not show yet.
  • Copy and sync: the wordings, in a search index. A nightly job re-indexes changed files and removes withdrawn ones, which a "changed since" check never lists.

A cache, a copy kept to answer faster (What Is Caching?), needs a target too: a policy status cached overnight isn't live.

Data the AI must never see

Anything in the prompt can come out again, in a draft, a log or at the model provider, and an injected instruction can make a model repeat its context. So filter before the prompt: never fetch it.

Nimbus's never list, illustrative: bank details, health declarations on travel policies and other people's claims. Keep it out in three layers:

  1. At the source: views and scopes, as in the lab.
  2. In your code: an allowlist, naming the fields you keep, not those you drop. Say the policy API returns 40 fields: keep the five the check needs, so new fields stay out. Fixed queries return only this policy's claims.
  3. In the input: claimants type bank details into emails, which no view filters. Mask them before the prompt, as LLM Guardrails redacts answers; patterns miss some, hence three layers.

Whether claims may reach a model provider at all is the security team's question, in the next lesson. The template collects it all, one row per source; the claims database row (illustrative):

SourceReads, and whyOwnerAccess methodMinimum permissionFreshnessNever sent to the AI
Claims databaseEarlier claims on the policy: duplicates, cited claimsClaims system teamRead replica, own loginSELECT on one viewSeconds behindBank details; other policies' claims

Check yourself

IT offers the claims database's admin login "to save a week", since your code only reads. Why say no?

A bug or an injected instruction can still steer the code, and an admin login lets it write or delete. A read-only view caps the worst case at reading four columns, logged under the assistant's name.

A policy cancelled at 09:00 shows as active in a 09:30 draft. What caused it, and what fixes it?

The status came from a copy, such as a nightly sync or a long cache. Policy status changes fast, so read it live, per claim.

The view hides bank_account, but a claimant types their account number into the email. Is the model protected?

No. The view filters what you fetch, not what arrives in the input, so mask the number before the prompt.

Go deeper