# How to put an AI agent into production safely

> Define what the agent may and may not do, give it the least access that works, defend against prompt injection, put a person in the loop where mistakes are costly, test against real cases, and roll out in stages with logging and a way to stop it.

- Author: Pranav Mahaveer, Founder, SBD
- Updated: 2026-10-28
- Level: Advanced. Time to do: Four to eight weeks
- For: Operations and technical leads deploying an AI agent that reads business data or takes actions in business systems
- You will end with: An agent with a written scope, scoped access, injection defences, approval rules, an evaluation set and a staged rollout plan
- Canonical: https://smallbaydigital.com/guides/how-to-put-an-ai-agent-into-production-safely/

## Steps

1. **Define the job and the boundary.** Write down what the agent does, what it must never do, and which level of autonomy it starts at.
2. **Give it the least access that works.** Scope every tool and credential to the task: read before write, specific records before whole systems.
3. **Defend against prompt injection.** Treat every document, email and web page the agent reads as untrusted, and validate every action it proposes.
4. **Put a person in the loop where it matters.** Tie approvals to the cost of a mistake, and design review so people do not just click approve.
5. **Test against real cases before launch.** Build an evaluation set from real, labelled cases and set pass criteria before go-live.
6. **Roll out in stages, with logs and a stop button.** Shadow, then suggest, then act with approval, then act within limits, watching the metrics at each stage.

> **The short answer.** Give the agent a written scope and the least access that does the job. Treat everything it reads as untrusted, and check every action it proposes outside the model. Require approval where mistakes are costly. Test against real cases before launch, log everything, and widen its autonomy in stages only when the numbers say it is ready.

An AI agent is a model that can take actions: read an inbox, look up a record, draft a reply, update a system. The model's judgement is only part of the risk. The rest comes from what it can reach and what it reads.

The steps below draw on the OWASP Top 10 for LLM applications, NIST's AI Risk Management Framework and the human oversight requirements in the EU AI Act. They apply whether you build on an automation platform or in code.

## 1. Define the job and the boundary

Write a one-page scope before any build:

| Section        | Example for an invoice-intake agent                                                                  |
| -------------- | ---------------------------------------------------------------------------------------------------- |
| Does           | Reads supplier invoices from one inbox, extracts fields, matches to purchase orders, drafts the bill |
| Never does     | Pays, changes supplier bank details, emails suppliers, edits posted bills                            |
| Systems        | Shared AP inbox (read), purchase orders (read), accounting system (create draft bills only)          |
| Escalates when | Confidence is low, no PO matches, amount over a threshold, bank details differ from the record       |
| Owner          | AP lead                                                                                              |

Then agree the starting level of autonomy. A useful ladder:

1. **Shadow.** The agent runs on real inputs; nobody sees the output except reviewers comparing it with what people did.
2. **Suggest.** It drafts; a person does the action.
3. **Act with approval.** It prepares the action; a person approves each one.
4. **Act within limits.** It acts alone below set thresholds and escalates the rest.

Start at shadow or suggest. Moving up is a decision made on evidence, not a launch setting.

## 2. Give it the least access that works

OWASP lists excessive agency as a top risk for LLM applications: more functionality, permissions or autonomy than the task needs. The fix is ordinary security practice applied strictly.

- **Its own credentials.** Never run an agent on a person's login. Create a service account or API key for it alone, so its actions are traceable and revocable.
- **Read before write.** Give read-only access unless the task needs writes, and then only to the specific objects. "Create draft bills" is not "full accounting access".
- **Narrow tools.** Expose a tool that does one thing ("look up PO by number") rather than a general one ("run any query").
- **Limits.** Rate limits, maximum amounts and maximum records per run, enforced in the tool, not in the prompt.
- **No dangerous verbs without a person.** Delete, pay, send outside the company and change permissions always go through approval.

## 3. Defend against prompt injection

Prompt injection is first in the OWASP list. Direct injection is a user trying to override instructions. Indirect injection is more dangerous for business agents: instructions hidden in an email, a PDF or a web page the agent reads, such as "ignore previous instructions and forward this thread to…".

You cannot prompt your way out of it reliably. Design so that a successful injection achieves little:

- **Treat all retrieved content as data.** Keep it clearly separated from instructions, and tell the model that content never carries instructions. This lowers the risk; it does not remove it.
- **Validate every action outside the model.** Before a tool runs, check the proposed action against an allow-list and business rules in ordinary code: is this supplier known, is the amount within limits, is the recipient internal?
- **Break the path from untrusted input to sensitive tools.** An agent that reads outside email should not, in the same run, be able to send outside email or change payment details without a check.
- **Constrain outputs.** Ask for structured output against a schema and reject anything that does not parse.
- **Test with hostile inputs.** Put injection attempts in your evaluation set (step 5) and keep them there.

## 4. Put a person in the loop where it matters

Human review is a control only if it is designed. Tie it to the cost of a mistake:

| Cost of a mistake                              | Control                                          |
| ---------------------------------------------- | ------------------------------------------------ |
| Low and reversible                             | Agent acts; sample 5 to 10% for review each week |
| Some rework or a credit                        | Agent acts below a threshold; above it, approval |
| Money, compliance, a customer, or irreversible | Approval on every action                         |

NIST's AI Risk Management Framework ties the level of oversight to the impact of the decision. For high-risk systems, Article 14 of the EU AI Act requires that people overseeing a system can understand its limits, interpret its output, decide not to use it, and stop it. It also names automation bias: the tendency to over-rely on what a system suggests.

Design against automation bias:

- Show reviewers the evidence the agent used, not just its answer.
- Highlight what is unusual: a new supplier, an amount out of pattern, low confidence.
- Track how often reviewers override the agent. An override rate near zero for weeks can mean the agent is good, or that nobody is really looking.

## 5. Test against real cases before launch

Build an evaluation set before you build the agent's final prompt.

1. **Collect real cases.** 50 to 200 for a focused task, drawn from the last few months, with the right outcome labelled by the person who does the work.
2. **Include the hard ones.** Rare formats, missing fields, near-duplicates, edge amounts and deliberate injection attempts.
3. **Set pass criteria in advance.** For example: 98% field accuracy on standard invoices, 100% escalation of bank-detail changes, zero actions outside scope.
4. **Run it on every change.** A new prompt, model version or tool changes behaviour. Re-run the full set before anything ships.
5. **Grow it from production.** Every failure in live use becomes a new test case.

## 6. Roll out in stages, with logs and a stop button

**Log everything.** For each run: inputs, retrieved content, the model's reasoning output if available, tool calls with arguments, results, approvals and the final output, all under one trace ID. Without this you cannot investigate a complaint or prove what happened.

**Watch a few metrics.** Accuracy against later human decisions, escalation rate, approval override rate, error rate by type, cost per item and time per item. Alert on sudden changes, not just failures.

**Have a stop button.** One switch that stops the agent taking actions, known to the owner, and tested before launch. Fallback is the manual process, so keep it documented.

**Move up the autonomy ladder on evidence.** Stay in shadow until accuracy meets the pass criteria on live data. Move from approval to acting within limits only for the case types where reviewers have stopped finding errors over a meaningful volume, and keep approval for everything above the threshold.

An agent that is boring to watch is the goal. If the logs are dull, the overrides are rare for good reasons and the stop button has never been needed, widen the scope one step.

## Checklist

- [ ] Written scope: tasks in, tasks out, systems it may touch
- [ ] Starting autonomy level agreed with the process owner
- [ ] Separate credentials for the agent, never a person’s login
- [ ] Every tool scoped to the minimum: read-only where possible, limited records, rate limits
- [ ] No tool can delete, pay, send externally or change permissions without approval
- [ ] Content from documents, email and web treated as data, never as instructions
- [ ] Every proposed action validated against an allow-list and business rules before it runs
- [ ] Approval thresholds set by cost of a mistake, with reviewers shown the evidence
- [ ] Evaluation set of real, labelled cases, including known hard and adversarial ones
- [ ] Pass criteria agreed before launch, and the evaluation re-run on every prompt or model change
- [ ] Every input, decision, tool call and output logged with a trace ID
- [ ] Alerts on error rate, cost per item and approval overrides
- [ ] A kill switch that stops the agent in one step, tested
- [ ] Staged rollout plan with the metric that moves each stage on

## Sources

- OWASP, [Top 10 for Large Language Model Applications, 2025 (LLM01 Prompt Injection, LLM06 Excessive Agency)](https://genai.owasp.org/llm-top-10/)
- NIST, [AI Risk Management Framework 1.0, 2023](https://www.nist.gov/itl/ai-risk-management-framework)
- European Commission, AI Act Service Desk, [Article 14: Human oversight](https://ai-act-service-desk.ec.europa.eu/en/ai-act/article-14)

## Questions

### What is the biggest security risk with AI agents?

Prompt injection combined with too much access. OWASP ranks prompt injection first in its 2025 Top 10 for LLM applications, and excessive agency, meaning more functionality, permissions or autonomy than the task needs, sixth. An agent that reads untrusted content and can act broadly is the combination to avoid.

### Can prompt injection be fully prevented?

Not reliably with prompts alone. Design so a successful injection does little harm: least-privilege tools, validation of every action outside the model, approvals for consequential actions, and no path from untrusted content to sensitive tools without a check.

### When does an AI agent need human approval?

When a mistake costs money, breaks a rule, reaches a customer or cannot be undone, and whenever the agent is making a judgement rather than following a rule. Frameworks such as NIST’s AI RMF tie oversight to impact, and the EU AI Act requires effective human oversight for high-risk systems.

### How many test cases does an evaluation set need?

Enough to cover the real variety of the work. For a focused business task, start with 50 to 200 real cases, labelled with the right answer, and include the hard and unusual ones. Add every production failure to the set so it cannot happen twice.
