You Can't Prompt a Padlock — or — How We Let Robots Touch Snowflake Without Handing Them the Keys
The other day I watched an agent try to drop a production table.
Not maliciously. That's the part that sticks with me. It hadn't been jailbroken, it hadn't been hijacked by some shady instruction smuggled in through a cell of a spreadsheet. It was just... tidying up. It had decided, with the serene confidence of a thing that has never once been fired, that a stale staging table was clutter, and that clutter should go. So it reached for DROP TABLE.
It did not get there.
And the why of that — the full argument for keeping an agent's judgment in your code instead of your prompt — I've written up elsewhere. This post is the how. This is the machine. Come look at the gears.
None of this would matter if robots got tired
Here's the setup. We run Claude Code in ephemeral containers — they spin up, do a job, and vanish. And we want them to query Snowflake, which is where all the interesting questions live. Easy, right? Hand the container a Snowflake credential and let it rip.
Except a Snowflake key-pair lives for months, has real blast radius, and the instant you paste it into a model's context you've handed your crown jewels to the single least trustworthy process in your whole stack — a thing that will cheerfully repeat anything it read five minutes ago to anyone who asks nicely.
So, no keys for the robot.
And there's a subtler reason, the one the dropped table taught me. A human analyst asked to reconcile two tables will try the obvious thing, and when it's slow, she'll sigh, get a coffee, and wonder if there's a better way. Her own laziness is a circuit breaker. An agent has no such governor. It will pursue its goal with bloody-minded, token-burning diligence — the obvious query, the clever one, the expensive one, the same expensive one again — and it will never, not once, think this feels wrong. It has the hands of a senior engineer and the self-preservation instinct of a while loop.
You cannot fix that with a nicer prompt. A prompt is a suggestion. What stops a DROP TABLE is not persuasion. It's a wall.
So we built the wall. It's called the Snowflake MCP Broker, and the rest of this post is a tour of it.
The phone-number trick
The core move is this: the agent never gets the key. It gets a phone number.
The broker is a long-lived HTTPS service sitting between the disposable agents and the durable accounts. An agent shows up with a scoped bearer token, references a connection by profile name — never credentials — and sends SQL. The broker does the rest: authenticates the token, checks the profile is in scope, runs the SQL through a policy engine, executes it under a least-privilege role, writes it all down, and hands back rows. The actual credential is decrypted for a heartbeat deep inside the broker and never, ever crosses back out.
One sentence to tattoo on the whole design: credentials are never a tool input and never a tool output. The robot could not leak the key if it tried, because it has never seen the key.
One app, two doors
The broker is one service, but it has two doors, and they do not share a lock.
The first door is /mcp — the data plane. This is where the agents knock. Auth is a bearer token; SQL goes in, rows come out, and that's all that goes in or out. The second door is /api — the control plane, where humans log in (local account or OIDC, session cookie) to set up profiles, paste secrets, and mint tokens. There's a third, the web console, but it's just the Vue app the humans click around in.
The point of two doors: the agent plane is deliberately the narrow one. An agent can run a query. It cannot create a profile, reveal a token, or peek at another user's anything. Different door, different key, different world.
And the data-plane door isn't naked, either — it sits behind a DNS-rebinding Host/Origin allowlist and a request-body cap, so nobody can rebind the endpoint out from under us or jam it with a ten-megabyte payload. Belt. Suspenders. We'll be seeing a lot of those two.
Follow the query, part one: the one that dies
Let's go back to that DROP TABLE, because the most instructive thing the broker does is say no fast.
The request arrives on /mcp, past the allowlist. The tool pulls the Authorization: Bearer header, and the broker resolves it — token, hashed lookup, out pops a principal: the human who owns this, the endpoint it came through, and the set of profiles that endpoint is allowed to touch. Good token. Carry on.
Profile prod? In scope. (If it weren't — if this token had never been granted prod — the broker would return the exact same error it gives for a profile that doesn't exist. Ungranted and unknown are one case, on purpose. The agent never learns the shape of what it can't reach.)
Now the interesting bit. Before a single packet heads toward Snowflake — before any credential is so much as decrypted — the SQL hits the policy engine. sqlglot parses it in the Snowflake dialect. It classifies the statement: this one's a DROP, which lands in the bucket marked DESTRUCTIVE. And the prod profile's policy is read-only.
Denied.
No connection opened. No key touched. No warehouse spun up. The whole thing cost a parse and a dictionary lookup, and the agent gets back a crisp little error explaining exactly which rule it hit. The attempt lands in the audit log — denials get recorded too, which turns out to matter — and we move on. The stale staging table lives to clutter another day.
That's the shape of a good guardrail: cheap, deterministic, and decided in code the model can't argue with.
Follow the query, part two: the one that lives
Now a legitimate one. SELECT * FROM orders, with a little context attached: {database: ANALYTICS, schema: PUBLIC}. Watch the whole conveyor belt run.
Token resolves, principal in hand. Profile in scope. The context gets frisked — every identifier checked against a strict bare-identifier grammar (no quotes, no semicolons, nothing that could wriggle out of a USE statement), checked against the profile's allowed databases and schemas, and bounced if the profile pins a warehouse the caller tried to override. Clean. And that ANALYTICS database now becomes the default for resolving unqualified names in the next step.
Into the policy engine. Parse — fine. Classify — a SELECT, a READ, allowed. Scope check — orders is unqualified, but we have a default database now, and ANALYTICS is on the allowlist, so it resolves and passes. (No default database and a scope list? We'd fail closed — the parser can't prove the table's in bounds, so it doesn't get the benefit of the doubt.) And because it's a lone SELECT, the engine quietly rewrites it with a LIMIT clamped to the profile's max_rows. The agent asked for everything. It's getting a thousand rows, and that's that.
Verdict: allow. The engine hands back the rewritten SQL, the row cap, a statement timeout, and a statement count. Now we spend money.
The query acquires against per-user, per-profile rate and concurrency caps — over the limit and it'd wait here, or bounce. It gets stamped with a QUERY_TAG that reads mcp:janet:prod:laptop:9f3c… — human, profile, endpoint, request id — so this statement is traceable to a person for the rest of its life. And then, finally, the executor earns its keep: it decrypts the profile's key-pair secret transiently, opens a connection under the least-privilege role, sets the timeout and the tag with ALTER SESSION, fires the USE statements for the context, and runs the SQL — telling the connector to expect exactly one statement, no more.
Rows come back. The executor fetches one more than the cap so it can honestly set a truncated flag, reads back CURRENT_WAREHOUSE, CURRENT_DATABASE, CURRENT_SCHEMA, CURRENT_ROLE so the caller can see the session it actually ran in, and the broker clamps the whole thing one more time against a global row ceiling on the way out — because the per-profile cap and the absolute cap don't trust each other either.
The call is logged. The metrics tick. And back to the agent go columns, rows, a truncated flag, the Snowflake query id, and the effective session.
Rows. Just rows. Exactly as promised.
Two locks on the same door
You might have noticed the policy engine is doing a lot of trusting of sqlglot. Parsers can be fooled. A gnarly enough CTE, a dialect quirk, a MERGE with a sneaky WHEN … THEN DELETE arm — what if one slips through classification?
It hits the second lock.
Every profile binds to a Snowflake role via role_override, and that role is least-privilege by construction. The prod role isn't told to be read-only; it is granted SELECT and nothing else. Physically. So the defense is two independent layers: a fast parse-time policy that leaks nothing and costs nothing on a deny, and a grant-time privilege that is coarse but cannot be talked out of a decision. Parsing can be fooled. Grants cannot. Run both, and a mistake in either is caught by the other.
That's the whole security spine, and neither half of it asks the model's opinion.
What the robot never sees
Back to that key, because it's the crown jewel and it deserves a paragraph.
The private key is write-only, end to end. A human pastes a PKCS#8 PEM into the console — and that's the last anyone sees of it in the clear. It's envelope-encrypted at rest; every read-back reports a boolean, secret_configured, never the bytes. At execution time the executor decrypts it, hands the DER straight to the connector, and lets it fall out of scope a few milliseconds later. It is never returned by an API, never written to a log, and never — never — placed in the model's context. The master key that wraps all this is itself pluggable (env, file, or Vault) and rotatable: one command re-encrypts every secret under a fresh key.
The agent brokers by name. It handles rows. It never holds a credential, because you can't leak what you were never handed.
(Oh — and the whole stack runs with no real Snowflake account if you want. There's a mock warehouse you can point it at, and everything in front of the mock is real: the auth, the policy, the rate limits, the audit, the tagging. Only the warehouse is pretend. It even exercises the decrypt path and then pointedly declines to send the secret onward. Faithful to the boundary, right down to the fake.)
Tell it the rules before it plays
One more design choice I'm fond of, because it's where "guard the robot" and "be nice to the robot" stop fighting.
The discovery tool, list_profiles, doesn't just list names. It hands back the structured policy — what classes of SQL are allowed, the row and timeout caps, the database and schema allowlists, whether the warehouse is pinned — and the default session context. So the agent sees the fence before it walks the field. It plans inside the lines because it can read the lines, instead of discovering them one denial at a time.
And when Snowflake itself rejects a query — a typo'd column, a missing object — we pass the real error back, code and SQLSTATE and all, so the agent can fix its own mistake and move on without a human in the loop. But a connection or credential failure? That gets flattened to a bland "couldn't establish the session." Transparency where it helps the robot think; opacity where it'd help a secret escape. The broker decides which error you're looking at. Not the model.
Four tools, all told — list_profiles, run_query, describe, list_objects — and the last three all funnel down the same guarded path you just watched. One spine. Every guardrail, every time, no matter which tool it grabbed.
The tab
Prevention is only half of containment. The other half is that nothing the agent does happens in the dark.
That QUERY_TAG rides all the way into Snowflake's own ACCOUNT_USAGE, so a credit spike arrives with a name on it — this person, through this token, running this. The audit log captures every call, success and deny and error alike. Prometheus has the aggregate. And a denial isn't just a wall the agent bounced off — it's a signal. A profile quietly racking up scope denials is telling you something: a too-tight allowlist, a confused agent, or someone's injection probe testing the fence. The thing you prevented becomes the thing you learn from.
An agent that can't be talked out of a decision, can't act unseen, and leaves a trail you can tune against — that's an agent you can actually let near production.
The lesson, and then I'll let you go
Strip away the Snowflake specifics and here's the whole thing in a sentence: the agent supplies the SQL, and the broker supplies everything else — including the judgment about what that SQL is allowed to do.
The model is clever and useful and fast, and it is also injectable, non-deterministic, and incapable of getting tired of a bad idea. So you don't ask it to be a wall. You build the wall — in the parser, in the grants, in the layers it can't reach — and then, precisely because the wall holds without its cooperation, you're free to make the tools generous: disclose the policy, accept a context, pass back the real error. The guardrails move somewhere the robot can't argue with them, and the robot gets a nicer workbench as a reward.
Coaching the model is a treadmill — every new jailbreak is another paragraph in a prompt that was never going to hold. A padlock is a padlock.
So: which of your agent's guardrails are currently living in a prompt, hoping very hard?
Go move them somewhere real.