The idea
If injection succeeds, the damage is limited by what the agent can do. A support agent with a generic run_sql tool can drop tables; one with get_order_status(order_id) cannot. Least privilege means narrow tools, scoped credentials and read-only access by default.
Design tools around tasks, not systems: refund_order(order_id, amount ≤ 100) instead of call_payments_api(endpoint, body). Give each tool its own credentials with the minimum scopes, and different agents different tool sets.
Review tool lists like you review IAM policies: every tool must justify its existence.
It is the most effective control against prompt injection, because it limits impact rather than trying to detect attacks.
Words to know
- Blast radiusHow much damage a compromised component can cause.
Try it without code
Shrink a tool
- Take your most powerful tool.
- Rewrite it as 2–3 narrow tools with tight arguments.
- List what an attacker can no longer do.
Use it in code
A narrow tool replacing generic SQL access.
# Bad: tool that runs any SQL the model writes
# def run_sql(query: str): return db.execute(query)
# Good: one task, validated input, read-only connection, scoped to the current user
def get_order_status(order_id: str, *, user_id: str, db_readonly):
if not order_id.isalnum() or len(order_id) > 12:
raise ValueError("invalid order id")
row = db_readonly.execute(
"SELECT status, eta FROM orders WHERE id = %s AND customer_id = %s",
(order_id, user_id)).fetchone()
return {"status": row[0], "eta": str(row[1])} if row else {"error": "not found"}Audit your agent’s tools, replace any generic tool with narrow ones, and document each tool’s permissions.
Common mistakes
- Passing the user ID as a model-controlled argument instead of from the session.
- One admin API key for every tool.