Skip to content
Français

Find unregistered AI

  • Lesson 19
  • 45 min
  • Module 6: Usage, evidence and shadow AI

Where we are

In the last lesson, we answered the governance board from the registry, the gateway's records and the audit trail. But those records cover only what passed the platform, and the report's first section already showed 17 findings outside the registry. The digest script never passed the gateway, so no report of ours would show it. In this lesson, we look for AI that nobody registered, the way a building manager finds a heater on a corridor socket, and we make registering easier than going around.

Plays from YouTube. Nothing loads from YouTube until you press play. Privacy

What you will be able to do

Find AI use that bypasses the platform: in the provider’s bill, in the network’s egress log and in code. Turn on the rule that makes the gateway the only way out, and see what it blocks. Then learn where the records stop: AI inside bought tools and on personal devices.

Before you startWhat to know and to have readyAbout 45 minutes

What you need to know

What you need on your computer

  • Your project ~/projects/ai-estate after the last lesson, with the estate running (python -m estate status) and its virtual environment active. RESOLVER_PROVIDER and RESOLVER_TOOLS must not be set in your terminal.
  • The labs repository in ~/projects/nextia-learning-labs, for this lesson’s files from the snapshot end-of-m06.

Tested on macOS (Apple silicon) with Python 3.12.13. The Windows (PowerShell) and Linux commands are written, not run. The bill, the expense line and the egress log are simulated from replayed traffic. The digest script, Fernway and its answer are constructed.

Think of an office building. The building has one main electricity meter, and each tenant’s office has its own sub-meter. Each month, the manager adds the sub-meters. One month, the main meter shows much more than the sum. Somebody uses power that no sub-meter counts.

The manager walks the corridors and finds the cause: a heater plugged into a corridor socket. Then she does three things. She locks the corridor sockets, so power flows only through the offices’ sub-meters. She keeps reading the main meter every month, because a lock does not stop every trick. And she asks why the tenant did it. The answer: getting a new socket in the office took three months. So she makes that faster, because a lock alone only teaches people to hide better.

Every app at Larkfield now has a registration, an identity and a gateway in front of it. Tomás says, “We have a gateway, so we are governed.” But the gateway sees only what passes through it. Nothing yet stops a script from calling a provider straight, with its own key, as the digest did.

The replayed month shows how much went around. The provider’s bill for September counts the calls of every key. Only 40,754 of 53,722 provider calls, 75.9%, came through the gateway’s own key. The other 12,968 went around it. Most of them were the apps before they moved, from 1 to 11 September. But some were not apps that Larkfield knew about at all.

The chart shows the egress log of the same month, day by day: provider connections from the gateway’s replicas, and from every other machine.

The replayed month's simulated egress log, summarised per day: connections to a model provider from the gateway's three replicas and from any other machine.
Text description of the chart

Two lines over the 30 days of September. Around the gateway: about 1,760 connections a day from 1 to 7 September, then 374 on the 8th, 84 on the 9th and 108 on the 10th, as the apps move one by one, and zero from the 11th, except one connection on the 14th, the 21st and the 28th: the digest, blocked. Through the gateway: zero until the 7th, then 1,383 on the 8th and about 1,750 a day after the 10th, with a peak of 2,563 on the 22nd, the day of the runaway loop. Over the month, 75.9% of the connections came from the gateway’s replicas.

Look at the single connections on the 14th, the 21st and the 28th. They are Mondays. Something tried to reach a provider every Monday and was blocked.

The idea: enforce what you can, find the rest

Section titled “The idea: enforce what you can, find the rest”

AI use that the organisation does not know about is often called shadow AI. A registry alone does not stop it, because the registry is a list. Registration is enforced only when there is no other way to reach a model. So the platform does two things, and it does a third before both.

First, make the gateway the only way out. Two rules do it:

  • Gateway-only keys. Only the gateway holds provider keys. The platform’s key inventory, config/provider-keys.yaml, lists each key that Larkfield has at a provider, with its owner and status. Today, az-key-9 is the gateway’s key. The old team keys, az-key-1 and az-key-2, are marked to_revoke.
  • Egress control. The network lets only the gateway’s machines connect to model providers. Egress is traffic that leaves the company’s network. Larkfield’s simulated network turned this rule on, on 12 September.

Second, look for what still goes around. Enforcement fails in small ways: a forgotten key, a laptop at home, a provider that the rule does not list. So the platform also reads three records that Larkfield already has: the bill, the egress log and the code. Two kinds of AI use leave no record, so a process must create one.

Third, and first in time: an easy path. If registering takes weeks, people go around, and every block only makes them hide better. At Larkfield, every app moved first (8 to 11 September), and the egress rule came after (12 September).

A table with five rows and four columns: source, it reveals, found in September, it cannot see. Provider bill: reveals a key ID that is not the gateway's key; found az-key-3, 202 calls, US$0.83, and fw-7Q2K, 1 call (Fernway); cannot see which app or person holds the key. Network egress log: reveals a machine that is not a gateway replica; found build-runner-3 to Fernway, 4 connections, 3 blocked, and priya-laptop to Azure, 204; cannot see use outside Larkfield's network. Keys in code: reveals a key or a provider address in a file; found weekly_digest.py lines 19 to 20, and 4 old keys in apps/replay.py; cannot see code that is not in the folders scanned. A note between the rows: above, found in records that Larkfield already has; below, no record exists, so a process must create one. The buying process: reveals a bought tool with AI inside; no finding, because it never passes the gateway; cannot see a feature switched on after the purchase. Asking people: reveals AI on personal devices and accounts; not in any record, only people know; cannot see what people do not want to say.
The sources that reveal unregistered AI. Three are records that Larkfield already has; two need a process, because nothing passes the gateway or the network.
Text description of the diagram

Five sources, each with what it reveals, what it found in September and what it cannot see. The provider bill reveals a key ID that is not the gateway’s. In September it found az-key-3, 202 calls for US$0.83, and fw-7Q2K, 1 call to Fernway. It cannot see which app or person holds a key. The network egress log reveals a machine that is not a gateway replica. It found build-runner-3 connecting to Fernway, 4 times with 3 blocked, and priya-laptop connecting to Azure 204 times. It cannot see use outside Larkfield’s network. Keys in code reveals a key or a provider address in a file. It found weekly_digest.py, lines 19 and 20, and 4 old keys in apps/replay.py. It cannot see code outside the folders scanned. These three are records that Larkfield already has. The last two need a process, because no record exists. The buying process reveals a bought tool with AI inside; it never passes the gateway, so there is no finding, and it cannot see a feature switched on after the purchase. Asking people reveals AI on personal devices and accounts; only people know, and it cannot see what people do not want to say.

  1. Copy the discovery code, the key inventory, its tests and the new README from the snapshot end-of-m06. In ~/projects/ai-estate:

    Terminal window
    S=../nextia-learning-labs/C32/snapshots/end-of-m06
    cp $S/estate/discovery.py estate/
    cp $S/config/provider-keys.yaml config/
    cp $S/tests/test_evidence.py tests/
    cp $S/README.md .
  2. Run the tests:

    Terminal window
    python -m pytest -q

    The last line says 194 passed, 1 deselected. The four new tests check the report’s sections, a bill line, an egress line and the code scan. One of them checks that a key is never printed whole. Your project is now the same as the snapshot end-of-m06.

python -m estate discover reads any number of bills (--bill), egress logs (--egress) and folders of code (--scan). It compares them with config/provider-keys.yaml and prints a finding for each line that does not belong to the gateway.

Worked example: two calls around the gateway

Section titled “Worked example: two calls around the gateway”

In a hurry, Priya runs the release judge from her laptop with her old personal key. And the digest still runs on the build machine. Make both happen in your estate, then find them.

  1. The judge, straight to the provider, without --via gateway, and the digest:

    Terminal window
    python -m apps.replay release-judge --units 2
    python apps/digest/weekly_digest.py
    release-judge: 2 requests straight to the provider | status {200: 2}
    answered by: chat-strong (gpt-6.1-sol-2026-09-29) x2
    tokens: 3,056 in, 246 out | cost: US$0.0086

    The digest prints its constructed summary and ends with (2764 tokens in, 152 out). Both calls worked: nothing stops them yet.

  2. Save the provider’s bill and the egress log into files, as finance and the network team would send them:

    Terminal window
    python -m provsim bill > state/bill.csv
    python -m provsim egress > state/egress.csv

    On Windows, -Encoding ascii keeps the files plain. PowerShell 5’s > writes UTF-16, which the discovery code cannot read.

  3. Read the bill first, as a person would:

    month,provider,key_id,deployment,requests,tokens_in,tokens_out,cost_usd
    2026-10,azure,az-key-3,chat-strong,2,3056,246,0.008572
    2026-10,azure,az-key-9,chat-small,27,44857,7556,0.008264
    2026-10,azure,az-key-9,chat-strong,10,19090,1291,0.051090
    2026-10,azure,az-key-9,embed-small,20,1446,0,0.000029
    2026-10,fernway,fw-7Q2K,fernway-swift,1,2764,152,0.001349

    Three lines are az-key-9, the gateway’s key: the last two lessons’ traffic. Two lines are not.

  4. Let the discovery code compare both files with the key inventory:

    Terminal window
    python -m estate discover --bill state/bill.csv --egress state/egress.csv
    Provider bills
    - 2026-10 azure key az-key-3 chat-strong: 2 requests, US$0.0086
    a key that nobody told the platform about
    - 2026-10 fernway key fw-7Q2K fernway-swift: 1 requests, US$0.0013
    a provider without a contract (fernway); a key that nobody told the platform about
    Network egress
    - build-runner-3 -> api.fernway.example: 1 connections (0 blocked) from … to …, key fw-7Q2K
    a machine that is not the gateway calls a model provider directly
    - priya-laptop -> larkfield-ai.openai.azure.example: 2 connections (0 blocked) from … to …, key az-key-3
    a machine that is not the gateway calls a model provider directly
    4 finding(s).
    Not found by any of these: AI features inside bought tools, and AI used on personal devices outside Larkfield's network. They enter the inventory through the buying process and by asking people.

    The times are left out here (…), because yours differ.

Read the four findings as two pairs. The bill says that az-key-3 is a key nobody told the platform about: it is not in config/provider-keys.yaml. But the bill cannot say who holds it. The egress log answers that: priya-laptop used az-key-3. Neither record alone names the person; together they do. The same is true for fw-7Q2K and build-runner-3, with one more fact: Fernway is a provider without a contract.

The gateway’s own lines, az-key-9 and the gateway-a, -b and -c machines, are not findings. The last line of the output is the most important one: it names what no record can find.

Now lock the corridor sockets. In the simulated network, SIM_EGRESS=gateway-only lets only the gateway’s machines reach a provider.

  1. Restart the estate with the rule on:

    Terminal window
    python -m estate down
    SIM_EGRESS=gateway-only python -m estate up
    python -m provsim status

    The status begins with "egress": "gateway-only".

  2. Try the two calls again:

    Terminal window
    python apps/digest/weekly_digest.py
    python -m apps.replay release-judge --units 2

    The digest stops with a long traceback that ends with:

    urllib.error.HTTPError: HTTP Error 403: Forbidden
    release-judge: 2 requests straight to the provider | status {403: 2}
    refused or failed: egress_blocked x2
    tokens: 0 in, 0 out | cost: US$0.0000
  3. Now the judge on the easy path, through the gateway, with its registration and its own credentials:

    Terminal window
    python -m apps.replay release-judge --units 2 --via gateway --seed 3
    release-judge: 2 requests through the gateway | status {200: 2}
    answered by: chat-strong (gpt-6.1-sol-2026-09-29) x2
    tokens: 3,045 in, 269 out | cost: US$0.0088
  4. Read the end of the egress log:

    Terminal window
    python -m provsim egress

    The last six lines in the course’s run. Each line starts with its time, left out here (…):

    …,build-runner-3,api.fernway.example,fernway,fw-7Q2K,200,11233
    …,build-runner-3,api.fernway.example,fernway,fw-7Q2K,403,11233
    …,priya-laptop,larkfield-ai.openai.azure.example,azure,az-key-3,403,6975
    …,priya-laptop,larkfield-ai.openai.azure.example,azure,az-key-3,403,7342
    …,gateway-a,larkfield-ai.openai.azure.example,azure,az-key-9,200,7172
    …,gateway-b,larkfield-ai.openai.azure.example,azure,az-key-9,200,7069

The rule blocked the call, and the log still recorded the attempt with status 403. That matters: a blocked attempt is a finding, not a solved problem. The digest still runs every Monday. Its key still works at Fernway from any network that is not Larkfield’s. Only the people who own the script and the key can end it.

In a real network, egress control is a firewall or proxy rule that allows the providers’ addresses only from the gateway’s machines. It costs the network team’s work and a list of providers to keep up to date. A new provider’s address stays open until someone adds it. Larkfield’s simulated rule is simpler: the simulator lets through only calls made with the gateway’s own key.

The third record is the code. A key or a provider’s address written in a file is a call waiting to happen.

Terminal window
python -m estate discover --scan apps
Keys and addresses in code
- apps/digest/weekly_digest.py:19: model provider address: http://127.0.0.1:8320/fernway/v1
model provider address in code
- apps/digest/weekly_digest.py:20: practice provider key: sim-fw-p...
practice provider key in code
- apps/replay.py:29: practice provider key: sim-az-s...
practice provider key in code
- apps/replay.py:33: practice provider key: sim-az-s...
practice provider key in code
- apps/replay.py:36: practice provider key: sim-az-d...
practice provider key in code
- apps/replay.py:38: practice provider key: sim-az-p...
practice provider key in code
6 finding(s).
Not found by any of these: AI features inside bought tools, and AI used on personal devices outside Larkfield's network. They enter the inventory through the buying process and by asking people.

The scanner is a few regular expressions in estate/discovery.py. It prints only the first 8 characters of a key, so the report never spreads a secret. The two digest lines are the Fernway address and the personal key. The four apps/replay.py lines are the apps’ old keys, from before the gateway: they are still in the code for the replayers’ direct mode. At Larkfield they are findings until the keys are revoked at the provider and deleted from the code. A real organisation runs a secret scanner on every commit as well, for example the one of its Git host.

Common mistake

The scan finds too much

Symptom: you scan the whole project instead of apps:

Terminal window
python -m estate discover --scan .

The output is long, and its last lines say:

38 finding(s).

Cause: the scanner reads every text file. It finds the simulator’s own accounts in provsim/accounts.py, the test keys in tests/, the gateway’s key file in state/secrets.json, and the hosts in the September report. Those are expected: the simulator must know its keys, and the gateway’s key must be in its own store.

Diagnose: look at the file of each finding. A finding in a test, in the simulator or in the gateway’s own state is expected. A finding in an app’s code is not.

Recover: scan the folders where apps live, as the platform does (--scan apps), and add each other folder with its own --scan. Never silence the scanner for a whole folder because of noise: that is how a real key in a test file stays unseen.

Two kinds of AI use leave no line in the bill, the egress log or the code that the platform reads.

AI inside bought tools. Suppose that Larkfield’s help-desk product adds an AI reply suggester in an update. The vendor calls its own model provider from its own servers. Customer messages leave Larkfield inside the help-desk product, so no Larkfield key, machine or file is involved. The gateway never sees it, and it never can. That is a limit of the course’s idea: the gateway sees model calls, not every use of AI. These tools enter the inventory through the buying process. The purchase form asks: does this product use AI? Which provider? What data does it send? Can we turn the feature off? Then the platform registers the product as a bought tool, with an owner, a risk tier and a review date. It gets no gateway credentials.

AI on personal devices and accounts. A customer message pasted into a chat assistant on a phone leaves no trace on Larkfield’s network. Only asking people finds it. A short survey and an amnesty help: “tell us, and we help you register it”. People answer honestly only when the answer helps them.

Why did Priya use her personal key? The judge started as a quick check before a release, and a key of her own was the fastest way to start. Why did Lee use Fernway? Lee already had an account. Each person chose the shortest path that worked.

So the platform makes the governed path the shortest one:

  • A short form for low and medium risk, which the platform checks in seconds (estate check), and a long form only for high risk. You met both in Module 3.
  • Credentials on the same day. estate credentials issue gives each agent its own secret, without a ticket to another team.
  • One setting to change. An app moves by changing its base URL and its credential. The aliases (chat-small, chat-strong) let old code keep its model names for a while.
  • Blocks after the path. At Larkfield, every app moved first, and the egress rule came after.
  • A reason to stay. The gateway gives the teams fallbacks during an outage, budget warnings and this module’s reports.

The next module measures the path: the share of calls through the gateway, and how often the gateway refuses a team.

When to use each source, and what it costs

Section titled “When to use each source, and what it costs”

The bill is the most complete record of paid use: the provider counts every call. But it arrives at the end of the month, and it names keys, not people. The digest ran on 7 September; its expense line came weeks later. Compare the bill’s total with the gateway’s records every month.

The egress log names machines, at once, and shows blocked attempts. But it sees only Larkfield’s network and the provider hosts that someone listed.

The code scan finds a problem before it runs. But it reads only the folders that you give it, with noise.

The buying process and people are the only sources for AI that never passes the gateway. They cost time and trust.

None of them prevents shadow AI. Together, with gateway-only keys, an egress rule and an easy path, they make it rare, visible and short-lived.

Your turn: this month’s report, and the September script

Section titled “Your turn: this month’s report, and the September script”

Two tasks. First restart the estate without the rule, so that the later modules work as written. Run python -m estate down, then python -m estate up. On Windows, run Remove-Item Env:SIM_EGRESS between them.

  1. This month’s estate report with its findings. Save the bill and the egress log again. Run estate discover on both and on apps. Then write the report with --out state/report.md, as in the last lesson, and count the findings in “Found outside the registry”.

  2. The unregistered script of September. Use only the three files in evidence/ and the code. Find the script that called a provider without a contract: its key, its machine, its file and lines, the day it last got an answer, and its owner. Start with:

    Terminal window
    python -m estate discover --bill evidence/azure-bill-2026-09.csv --bill evidence/fernway-expense-2026-09.csv --egress evidence/egress-2026-09.csv --scan apps
  3. Decide what Larkfield should do with the script, and write your reason in one sentence.

Check your answers

1. In the course’s run, the report’s section 1 said:

Found outside the registry (10 findings, `python -m estate discover`):

The 10 are the two bill lines (az-key-3 and fw-7Q2K), the two egress lines (build-runner-3, 2 connections with 1 blocked; priya-laptop, 4 connections with 2 blocked) and the six code findings. The blocked attempts are still findings. The report reads state/discovery.json, which the last estate discover wrote, so run discover before report.

2. The discovery prints 17 findings for September. The trail of the script uses four of them and one file of people:

A flow from top to bottom. The expenses: fw-7Q2K, fernway-swift, 1 call, US$0.0013, a key that is not in the inventory. The egress log, which machine: build-runner-3 to api.fernway.example, 4 connections, 3 blocked from 12 September. The code scan, which file: apps/digest/weekly_digest.py lines 19 to 20, a Fernway address and a personal key. Who owns it: Lee's Monday job; config/people.yaml: usr-lee left on 2026-08-31. What now? Register it with a new owner, on a capability, through the gateway; or retire it, and close the Fernway account.
From one expense line to the script and its owner. Each record answers the question that the one before cannot.
Text description of the diagram

Start with the expense line: the key fw-7Q2K, the model fernway-swift, one call for US$0.0013, and a key that is not in the inventory. The bill cannot say which machine used it, so the egress log answers: build-runner-3 connected to api.fernway.example 4 times, and 3 were blocked from 12 September. The egress log cannot say which program, so the code scan answers: apps/digest/weekly_digest.py, lines 19 and 20, has a Fernway address and a personal key. The code cannot say who owns it: it was Lee’s Monday job, and config/people.yaml says that usr-lee left on 31 August. Then decide: register it with a new owner, on a capability, through the gateway, or retire it and close the Fernway account.

The egress lines for build-runner-3 give the days:

2026-09-07,build-runner-3,api.fernway.example,fernway,fw-7Q2K,200,1
2026-09-14,build-runner-3,api.fernway.example,fernway,fw-7Q2K,403,1
2026-09-21,build-runner-3,api.fernway.example,fernway,fw-7Q2K,403,1
2026-09-28,build-runner-3,api.fernway.example,fernway,fw-7Q2K,403,1

It got its last answer on Monday 7 September. The egress rule blocked it on the next three Mondays. These are the three single connections in the chart. The registry cannot register it as it is: its owner, usr-lee, has left, and the registry refuses an owner who left.

3. Either answer is good with a reason. Register it if the Monday summary is useful. It needs a new owner on the service team, fast-small instead of Fernway, and its own credentials. The gateway then checks the data class of every message. Retire it if nobody wants to own it: delete the script and its job, and ask Fernway to close the account and delete the data. In both cases, record the shadow-AI incident’s end. The final assignment asks you to do one of them.

Check your understanding

Tomás says: 'We block all egress to providers except from the gateway, so shadow AI is solved.' Give two ways AI use still happens outside the gateway, and how Larkfield would learn of each.

Show the answer

A person uses a personal key or account from home or on a phone, outside Larkfield’s network: the egress rule never sees it. Larkfield learns of it only by asking people, or from a bill if the key is on Larkfield’s account. A bought tool with AI inside calls its vendor’s model from the vendor’s servers: Larkfield learns of it through the buying process. A third answer: a new provider that the egress rule does not list. The egress log shows it only if someone looks for AI hosts there.

Check your understanding

The bill shows az-key-3 with 202 calls. Why is the bill alone not enough to act, and which record completes it?

Show the answer

The bill names a key, not a person or an app, and the key is not in the inventory, so nobody knows who holds it. The egress log completes it: priya-laptop used az-key-3. With both, Kwame can ask Priya, move the judge to its registration and its credentials, and revoke the key at the provider.

Check your understanding

Practical: add a new key to config/provider-keys.yaml for az-key-3 with status to_revoke, and run the September discovery again. What changes in the finding, and why is this better than deleting the line from the bill?

Show the answer

Add a line under keys:, for example az-key-3: {provider: azure, owner: usr-priya, purpose: Priya's personal key, from before the gateway, status: to_revoke}. The finding changes from “a key that nobody told the platform about” to “Priya’s personal key (owner usr-priya): still used, so not every call passes the gateway”. The text after the comma in purpose is not printed. In this one-line YAML form, a comma ends the value, as in the file’s other lines. The key is now known and owned, but it is still a finding until nobody uses it. Deleting the line would hide the use; the inventory records a decision and keeps the evidence. Undo the change afterwards with git checkout config/provider-keys.yaml, or copy the file from the snapshot again, so your project matches the snapshot.

Recap

  • A registry alone does not stop shadow AI. Registration is enforced only with gateway-only keys and an egress rule, and only after an easy path exists.
  • python -m estate discover --bill … --egress … --scan … compares the bill, the egress log and the code with the key inventory. In September it found 17 findings, among them Priya’s key and the Fernway digest.
  • Each record answers part of the question: the bill names the key, the egress log the machine, the code the file, the people list the owner.
  • The egress rule blocks the call and still logs the attempt: found, not prevented. The digest’s key still works outside Larkfield’s network.
  • AI inside bought tools and on personal devices passes no record of the platform. The buying process and asking people bring them into the inventory.

Your project is now the same as the snapshot end-of-m06, with 194 tests. You can now read the estate’s usage, answer the board from evidence and find what went around the platform. But Larkfield built all of this itself. Next, in Module 7, we compare our gateway with the products that do the same job, and decide when to build and when to buy.

Next: Gateways compared