In the wild west of agency AI, the scariest bug isn’t a crash—it’s a perfectly coherent social post written in the wrong brand’s voice, published to the wrong client. iboson, writing from the trenches of Blooming, an agency platform running 40+ AI agents, argues that human intuition about client separation doesn’t scale to autonomous systems. If an agent can see ten clients’ data, it will eventually hallucinate a crossover. The solution isn’t better prompting; it’s rigid architectural isolation.
Layer 1: The Database Says No
Don’t trust your Python code to remember a WHERE tenant_id clause on every query. Blooming enforces isolation at the PostgreSQL level using Row-Level Security (RLS). By creating a specific agent_worker role and policies that bind visibility to a session variable app.brand_id, the database itself refuses to return or write rows belonging to other tenants. They tested this on PostgreSQL 16, confirming that an unset brand ID results in zero rows returned, failing closed by default.
The Pooling Pitfall
A critical implementation detail caught the Blooming team during testing: connection pooling can leak state. On a fresh connection, an unset variable is NULL, but on a pooled connection reused from a previous task, it might read as an empty string. If you cast that directly to a UUID, it throws a syntax error. The fix is wrapping the setting in NULLIF(current_setting('app.brand_id', true), '')::uuid to normalize both cases. Also, always use SET LOCAL (via set_config(..., true)) to ensure the variable scope dies with the transaction, preventing leakage into the next task.
Layer 2: Context Hygiene
Even with a locked-down database, the prompt is a vector for contamination. If you retrieve "similar" posts from a vector store without filtering by tenant, or if you share few-shot examples across brands, the agent will bleed voice. Blooming’s approach is to assemble context from scratch for every single task, pulling only approved content for that specific brand ID. There is no shared memory between tenants. If an agent keeps notes, they are stored per brand ID and protected by the same RLS policies. One long session working for multiple brands is a recipe for disaster; fresh context is mandatory.
Layer 3: The Human Firewall
The final check is a deterministic output scan. Before a draft is ever seen, a trusted service scans the text for mentions of *other* brands’ names, handles, or product terms. This check runs outside the agent worker because it needs global knowledge of all brand identifiers. A hit doesn’t trigger an error; it flags the draft for human review. The philosophy is clear: agents draft, schedule, and sort, but a human who knows the client presses the publish button.
Key Takeaways
- Fail Closed: If
app.brand_idisn't set, RLS ensures the agent sees zero rows, not all rows. - Vector Store Parity: Your embedding store needs the same tenant isolation as your relational DB; post-filtering results is insufficient.
- No Cross-Tenant Few-Shots: Never use examples from Client A to teach the model how to write for Client B.
- Deterministic Guards: Use regex-based output checks for brand name leakage as a final safety net before human approval.
The Bottom Line
Stop trying to prompt your way to security. If your AI agent architecture relies on the model "remembering" which client it’s talking to, you’re already leaking data. Isolation must be enforced by the database and the context assembler, not the LLM.