
You never rely on a prompt that says "only show data for company A." Prompts can be talked around. Isolation has to live in the backend and the database, where a clever input can't change it.

How it works
- From login, not from the request. Middleware verifies the user's token and puts
tenant_idinto the request context. That's the only place it comes from. - In the database. Every table carries
tenant_id, and Postgres row-level security (RLS) enforces it, so even a buggy query can't read another tenant's rows. - In vector search. The vector index is filtered by tenant before the similarity search, never after.
- In caches. Redis keys are namespaced per tenant, like
t:42:.... - Not in tool arguments. The LLM never gets
tenant_idas a parameter it can fill in. The backend injects it.
Why it matters for agents
An agent that can call tools can be tricked into calling them with different inputs. If tenant_id were a tool argument, a prompt injection could ask for another company's records. When the backend injects it from the verified session, that whole class of attack doesn't exist. ResolveOps does tenant isolation in the database schema for this reason.
Key takeaways
- 01tenant_id comes from verified auth, nowhere else.
- 02Enforce it in Postgres, vectors and cache keys.
- 03The model never sees tenant_id as an input.