How to Stop AI Agents Creating Duplicate ERP Transactions
How do you prevent AI agent duplicate transactions on retry?
Give each intended business transaction a stable idempotency key, keep a durable execution record, and make the ERP write path enforce duplicate protection. When a request times out, treat its outcome as unknown: reconcile with the ERP before deciding whether another write is safe. An instruction telling the agent “do not create duplicates” belongs in the prompt, but duplicate protection belongs in the transaction system.
Design the workflow around one question: does this attempt represent a new business action, or another attempt to complete the same action?
Why is a timeout an uncertain outcome?
Treat a timeout as meaning only that the caller stopped waiting. Do not assume the ERP accepted, rejected or completed the write.
Consider an illustrative purchase-order workflow. The agent submits an approved order, the ERP creates it, and the response never reaches the caller. From the agent's perspective, the request failed. From the business's perspective, the order already exists.
For your workflow, distinguish these outcomes:
| Outcome | What the workflow knows | Next step |
|---|---|---|
| Confirmed success | The ERP returned a completed result | Store the ERP reference and finish |
| Confirmed rejection | The ERP confirms that no transaction was created | Correct the problem before another attempt |
| Still processing | The ERP reports work in progress | Check status without submitting another create request |
| Unknown | The response is missing or inconclusive | Reconcile before deciding whether to retry |
Do not classify every error response as a confirmed rejection. Define that classification from the ERP's documented behaviour.
What should an idempotency key identify?
Use an idempotency key to identify one intended business operation, rather than one network attempt.
For example, assign a key when an approved request becomes eligible to create a purchase order. Preserve it through timeouts, worker restarts and repeated tool calls. A separate approved order needs a separate key, even if its supplier and line items happen to match.
Specify these rules:
- Create the key in application code before the first write.
- Scope it to the relevant organisation and operation.
- Reuse it for every attempt at that operation.
- Bind it to the approved transaction details.
- Reject reuse with different details.
- Keep its duplicate-protection record for the full supported recovery period.
Design the check around the API's documented contract, including key scope, retention and concurrent-request behaviour. Do not assume that adding a request header provides protection.
If the ERP supports idempotency, confirm exactly what it guarantees. If it does not, investigate whether it can enforce a unique external reference at creation.
What belongs in the durable execution record?
Keep the execution record in persistent application storage. Make it the workflow's source of truth for progress, rather than asking the model to remember which writes succeeded.
For each operation, record:
| Field | Purpose |
|---|---|
| Operation identity | Connect attempts to the same intended action |
| Idempotency key | Carry the stable identity into the write path |
| Approved payload fingerprint | Detect changed details under the same key |
| Current state | Distinguish pending, submitting, unknown, completed and rejected |
| ERP transaction reference | Identify the confirmed result |
| Attempt history | Preserve responses and reconciliation decisions |
| Approval reference | Connect the action to the permission that allowed it |
Store only the business data needed for execution and recovery. Apply access controls to transaction details and execution history.
Require workers to claim an operation atomically before submitting it. Completion should store the ERP reference and the completed state together.
However, do not treat this local record as sufficient protection. A worker can stop after the ERP commits but before local completion is saved. Treat a local database update and a remote ERP write as separate operations unless an explicit transaction mechanism joins them.
That gap is why recovery needs ERP-side protection or reliable reconciliation.
How should reconciliation work before a retry?
Reconciliation should answer whether the intended transaction exists, is still processing, or can safely be submitted again.
Use the strongest supported lookup: operation status, an idempotency record, or an exact external reference. Compare the returned transaction with the approved details.
Define explicit recovery branches:
- A matching completed transaction exists: record its ERP reference and finish.
- The operation is still processing: continue status checks within a bounded recovery policy.
- The reference exists with different details: stop and investigate the conflict.
- The result is inconclusive: hold the operation for reconciliation or human review.
- Absence is authoritative and resubmission is protected: retry with the original key.
Treat “search returned nothing” cautiously. Before using absence as evidence, establish whether the lookup covers the relevant records and whether a pending write could appear later.
If those guarantees are unavailable, stop automatic resubmission. A person may need to resolve the uncertainty. Give them the intended action, available evidence and permitted next steps, as described in where approval steps belong in AI agents.
What does a safe retry look like?
Consider this illustrative example: an approved request should create one purchase order for 24 replacement parts.
The application assigns an operation identity and key, then saves the approved details before submission.
The ERP receives the write, but the connection times out. The workflow records an unknown outcome. It does not create a new operation or ask the agent to reconstruct the order.
On recovery, it checks the ERP using the original key or unique external reference. If the order exists and matches, it saves that reference and finishes.
If the ERP's supported recovery mechanism establishes that resubmission is safe, the workflow sends the same approved payload with the same key. If the outcome remains uncertain, it holds the operation.
Acceptance criteria should cover more than the ordinary success path:
- Repeated requests return or recover the same ERP transaction.
- Concurrent attempts cannot create separate transactions.
- Changed details under an existing key produce a conflict.
- Recovery works after a stop immediately following the ERP write.
- Unresolved outcomes stay visible and have an owner.
Use these as pilot checks, alongside normal business acceptance criteria. Running an AI pilot that ends in a decision explains how to set that boundary.
What common mistakes should you avoid?
Generating a new key on every retry. Preserve the operation identity throughout recovery. A retry should not become a fresh business request.
Searching, then creating without enforced uniqueness. Do not rely on that sequence as your concurrency control. Require the receiving write path to reject duplicate operation identities.
Retrying every failure automatically. Classify outcomes first. Waiting longer between attempts does not resolve uncertainty.
Allowing silent payload changes. If the quantity, recipient or other approved detail changes, stop and apply the appropriate amendment or new-approval process.
Treating approval as execution protection. Approval establishes permission. Keep duplicate protection active after approval.
Marking a whole workflow complete after one write. For a process that creates an order and then reserves stock, track each write separately. Resume from the unresolved step.
When does this approach need additional controls?
Idempotency protects the identity of an operation. It does not determine whether the operation was correct or authorised.
If the agent creates two separate operation identities for the same underlying request, per-key protection is insufficient. Define business-level duplicate rules for incoming requests, while allowing legitimate repeat orders.
Likewise, a completed transaction should not be silently rewritten during retry recovery. Route corrections through the ERP's supported amendment or reversal process.
Where the ERP offers neither enforceable uniqueness nor dependable outcome lookup, set a narrower automation boundary. Let the agent prepare the transaction and route uncertain writes to a person.
A related risk is two writers changing the same record; see how to stop agents overwriting the same CRM record.
Frequently asked questions
Is a prompt instruction enough to prevent duplicates?
No. Require application-level operation identities, persistent records and an enforced write contract. Keep the prompt instruction as guidance for the agent.
Should every timeout trigger another write?
No. Classify the outcome and reconcile first. Retry only when the documented write contract makes repetition safe.
Can a duplicate have a different idempotency key?
Yes, under the proposed design two separately assigned keys represent separate operations. Add business-level checks to catch repeated intake of the same request.
What should we ask an implementation partner?
Ask them to demonstrate a timeout after ERP creation, a restart before local completion, concurrent submissions and conflicting payloads. Require evidence of the resulting ERP records, not just a successful tool response.
Our custom AI agent service covers agents connected to business systems. Define the write and recovery contract before granting an agent permission to post transactions.