Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 109/ 160
06. AI Security

Least-privilege Tools

Expose only the minimum tool capabilities an agent needs for its job.

IntermediateScope · Read-only3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

In plain words

Only give the AI the small set of tools it truly needs, in the safest form possible, so a mistake or trick can't cause big damage.

Think of it like…

Giving a new contractor a key card that opens only the rooms they need during working hours, instead of a master key: if the card is stolen or misused, the damage is contained to a few rooms.

Where you’ve seen it

An analytics assistant first had run_sql with a service account that could read 40 tables and write to all of them. A red team's injected document convinced it to dump customer emails and drop a staging table. The redesign exposes four tools: sales_summary(region, month), top_products(region, limit<=20), get_order(order_id) (checks the order belongs to the caller's account) and export_report(report_id); each runs a parameterised query against a read-only role limited to 3 views, with a 100-row cap, a 5-second timeout and 30 calls per minute per user. The reachable data falls from 40 tables to 3 views, writes drop to zero, and the maximum rows returned per call from millions to 100. The team's risk estimate (illustrative): 5% monthly chance of agent compromise × $2,000,000 impact of a full data exposure = $100,000 expected monthly loss; with least privilege the worst case is one customer's order data, about $2,000 of impact, so the expected loss is 5% × $2,000 = $100. Capability reviews happen whenever a tool is added.

Words you’ll hear

Blast radius
The damage possible if an agent or credential is compromised or errs.
Narrow tool
A tool with a specific purpose and typed, validated parameters.
Capability cut
Removing or restricting a tool, scope or privilege from an agent.
Read-only by default
Granting write or delete rights only where explicitly needed.

Visual diagram

Loading interactive diagram

Theory & deep dive

Designing narrow tools

Prefer purpose-built tools over general-purpose ones. A tool that takes an order id and returns that order is auditable and testable; a tool that takes SQL, a URL, a shell command or arbitrary code gives the model (and anyone who controls its input) the full power of the underlying system. Constrain each parameter: enums for categories, ranges for numbers, regexes for identifiers, maximum sizes, and server-side ownership and policy checks (the order belongs to the caller). Return only what the model needs (minimal fields, truncated lists) so a compromise exposes less. Separate read and write tools, and split agents by role (a research agent with read-only tools; an action agent with a few write tools behind approvals).

Make capabilities task-scoped: expose tools dynamically based on the user's request and the conversation state (a billing question doesn't need the "delete account" tool), and remove tools the current step doesn't use. Where a generic capability is unavoidable (code execution, web fetch), wrap it in controls: a sandbox with no credentials, a network allowlist, resource limits and output caps (see tool sandboxing). Keep tool descriptions precise but free of secrets, and remember that every tool definition costs tokens and expands the injection surface, so fewer, better tools are also cheaper and more reliable.

Replacing a generic tool

Before: run_sql(query: string). After: sales_summary(region: enum[EMEA, AMER, APAC], month: string /^\d{4}-\d{2}$/) executing a parameterised query on a view. The model can still answer sales questions, but cannot read customer tables or run DROP.

Key takeaway: Replace generic powers with narrow typed tools, split read and write, and scope tools to the task.

Credentials, limits and governance

Credentials should be scoped and short-lived: use the end user's identity or a delegated token with minimal scopes rather than a shared service account, issue tokens that expire in minutes, and prefer read-only database roles restricted to views. Enforce limits in the tool layer: row caps, byte limits, timeouts, per-user and per-tool rate limits, and daily budgets for costly actions. Add approvals for any irreversible or high-impact write, and idempotency keys so retries don't duplicate actions. Log every call with the user, tool, arguments and decision (see audit logging) and alert on unusual patterns such as a burst of order lookups or a tool used outside its normal context.

Govern the tool set like an API surface: maintain an inventory (tool, owner, data touched, scopes, approval rules), review it whenever a tool is added or changed, run capability cuts exercises ("what's the minimum this agent needs?"), and test with an adversarial suite that tries to make the agent call tools out of scope or with malicious parameters. Measure the blast radius in concrete terms (tables reachable, rows per call, write operations, money movable per day) and reduce it over time. Quantify risk with likelihood times impact to prioritise: cutting impact from $2,000,000 to $2,000 dwarfs any reduction in the probability of compromise, which is hard to push below a few percent for LLM agents.

Expected loss

5% monthly chance of manipulation × $2,000,000 impact = $100,000 expected loss. After scoping, impact is limited to one customer's order data (~$2,000): 5% × $2,000 = $100. The probability didn't change; the blast radius did.

Key takeaway: Use scoped short-lived credentials, enforce limits and approvals in the tool layer, inventory tools and measure blast radius.

How it works, step by step

Step 1 of 4
Security + engineering

1. Inventory current capabilities

List every tool the agent has, the credentials it uses and the data and actions reachable.

run_sql: 40 tables, read + write
Key numbers at this step
Measure
blast radius

When to use it & trade-offs

What it is

Least-privilege tools means giving an agent only the capabilities its task requires, scoped as tightly as possible. Instead of a generic run_sql(query) or http_request(url), expose narrow, typed tools such as get_order(order_id) and create_refund_request(order_id, reason) with constrained parameters (enums, ranges, ownership checks), read-only by default, credentials that are scoped and short-lived, per-tool rate limits and an explicit allowlist per agent and per task. The goal is to cap the blast radius: if the model is manipulated by prompt injection or simply makes a mistake, the worst thing it can do is small and recoverable.

Why it matters: An LLM agent will eventually be tricked, confused or wrong. Security that depends on the model behaving can't hold; security that limits what a misbehaving model can touch does. Excess capability is the most common cause of serious incidents (OWASP's "Excessive Agency"): an agent with database admin rights, shell access or write access to production because it was convenient during development.

When to reach for it

  • Any agent with database, file, network or API access
  • Reducing the impact of prompt injection
  • Compliance reviews of agent capabilities

When to avoid or be careful

  • Service accounts with broad write access
  • Arbitrary SQL, shell or URL tools for the model
  • Leaving unused tools exposed

Tool design choices

Narrow typed tools
Best for: Most agent tasks

Strengths: Small blast radius; auditable; testable.

Watch out: More tools to build and maintain.

General-purpose tools (SQL, shell, HTTP)
Best for: Exploration in isolated sandboxes

Strengths: Flexible; fast to build.

Watch out: Unbounded power; high injection risk.

Read-only first with approvals for writes
Best for: Agents that must take some actions

Strengths: Safe default; human control for risky steps.

Watch out: Adds friction for write paths.

Interview signals & numbers to know

When this topic comes up

  • “The agent has admin access”
  • Excessive agency
  • Read-only by default
  • Blast radius
  • Per-user scoped tokens

Benchmarks & rules of thumb

40 → 3 -
tables reachable before and after
100 rows · 5 s · 30/min -
example per-call and rate limits
$100,000 → $100 -
expected monthly loss after cutting impact

Common mistakes & follow-ups

Common interview mistakes

  • Putting a read-write production credential in the agent for convenience.
  • Allowing the model to choose arbitrary table names or URLs.
  • Never removing tools that are no longer needed.

Likely interviewer follow-ups

  • How would you scope tools for a data-analysis agent?
  • Why reduce impact rather than only probability?
  • What belongs in a tool inventory?
Interview tip: Quantify blast radius (tables, rows, writes) before and after. It makes the security improvement concrete.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Least-privilege Tools with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
Data Leakage
Next topic
Tool Sandboxing