Build notes18 Oct 20264 min

Designing safeguards for an AI that writes integrations

CloudEagle's take-home asked for AI that generates integration code from an app's API docs: an API client, auth, user and usage retrieval, error handling, pagination and logging. Taken literally, that gives you a new codebase for every app, written by a model and reviewed by an IT admin who can't read it. So before designing safeguards, I changed what the AI is allowed to produce.

The AI fills a form, not a file

Auth, pagination, retries and logging work the same way for every REST app. Only the specifics change: which header, which cursor field, which endpoint lists users. So the AI fills in a declarative connector form, and one hardened engine runs every form. That move is itself the biggest safeguard: the form can only express GET or HEAD calls to one host. Whatever the model gets wrong, it can't express a write.

"Use a read-only token" isn't a control

The obvious answer to "how do we stay read-only?" is "ask for a read-only token". Vendor auth docs showed why that can't carry the weight. Legacy Calendly personal access tokens keep full access. Okta API tokens have no scopes of their own: they inherit the role of the admin who created them. So the token is guidance, and read-only is enforced in three places a token can't override:

  • the form schema accepts only GET or HEAD;
  • the engine's HTTP client is hard-coded to GET or HEAD and re-checks the host on every request;
  • an egress proxy allows only the confirmed vendor host and only GET, and logs every call, so "0 write calls" is something we measure, not something we claim.

The model never sees what it doesn't need

The admin pastes the token at one gate, and it never reaches the AI. When a test fails, the AI sees the shape of the response, never its values, with emails and IDs masked. The model has no tools either: it can only return a form, which a validator checks. API docs are treated as untrusted input, because docs can carry prompt injection like any other text.

A loop that can't cheat

When the first test fails, the AI repairs the form in test mode, with at most 3 attempts and 25 requests. A loop like that can game its own tests: it could make "last active" pass by mapping it to the account creation date. So the engine owns the checks and the AI can't edit them, and any fix that changes what a field means is flagged for the human at approval. Fixed rules decide that, based on which part of the form changed. A model doesn't.

Failures that look like success

One Okta detail changed the design. A token without an admin role doesn't fail: the users endpoint returns 200 with an empty list. A naive test passes that as "connected, 0 users". In this design, nobody found is a failure, and the Connect screen shows how many members the token can see before any test runs.

The gate that matters is ours, not the vendor's

My first instinct was "build against the vendor's sandbox, then promote to production". Long-tail apps rarely have a data sandbox, so that plan breaks on most of them. And the real risk of a read-only connector isn't in the vendor's production. It's in CloudEagle's: a bad mapping marks active people as idle, and an automation reclaims their seats. So new connectors go live in shadow mode. Their data is visible and labelled "Custom (AI-built)", but no automation acts on it until 3 clean syncs and the owner marks it trusted. Each last-active value carries its source and a confidence based on the type of evidence, and a proxy signal never triggers a reclaim on its own.

The one I'd defend in any interview

If I could keep only one, it would be read-only by construction. Prompts drift, models change and tokens are over-privileged more often than not. A system that physically can't send a write doesn't depend on any of those going right. The others limit how wrong the AI can be. This one limits how much damage being wrong can do.

Case study · CloudEagle conceptCOMING SOON

Talk to Aswin.

If the fit check sent you here, the role is already filled in. I read every message myself.

+91 98169 23863 · calls Mon–Fri, 10am–7pm IST · WhatsApp anytime