AI Integration with ERP (Optima, SAP, Subiekt) — Building a Decision Layer Over Your Business Data
Your ERP stores the facts about your business — inventory, invoices, margins, clients. AI can turn those facts into decisions: automatically, safely, and in line with your system's logic. Learn the Closed-Loop AI architecture for Optima, SAP, and Subiekt.
Your ERP system is the heart of the company. It stores inventory levels, invoices, margins, contractors, and the full history of operations. The problem is that in most companies this heart doesn't think. The data is there, but to use it a person must manually transcribe, analyse, check, and correct it.
AI integration with ERP is not about "connecting ChatGPT to invoices". It is about building a decision layer that understands transactional data, enforces business logic, and executes operations in the ERP according to the system's rules.
In this article I show what that architecture looks like in practice — from choosing the right integration method, through JSON Contracts and RAG, to test environments and security controls that no production system should launch without.
Which ERP Systems Can Be Integrated with AI?
In practice I most often work with three system families: Comarch ERP Optima, SAP (ECC / S/4HANA), and Subiekt nexo / GT. Each has a different communication architecture — which is why the approach must always be tailored to the specific system.
| ERP System | API Interface | Integration Method | Difficulty |
|---|---|---|---|
| Comarch ERP Optima | REST API + Sfera (COM) | Sfera API or SQL database with triggers | Medium |
| SAP ECC / S/4HANA | OData / BAPI / RFC | SAP Integration Suite / BTP | High |
| Subiekt nexo / GT | Sfera SDK (.NET) | .NET Adapter + InsERT SDK | Medium |
| Symfonia ERP | REST API | Native API + webhook | Low–Medium |
There is no "off-the-shelf AI plugin for ERP". Every deployment must be architecturally designed for the specific infrastructure — which is exactly why 90% of "AI ERP integrations" on the market end up being nothing more than invoice OCR and manual clicking.
Closed-Loop AI ↔ ERP Architecture
A professional integration always operates in a closed decision loop. The ERP generates an event (new invoice, purchase order, warehouse document), middleware captures it, data is validated, AI makes a decision, and only then — through the official ERP API — a write occurs.
/// CLOSED-LOOP: AI ↔ ERP PIPELINE
The most important engineering rule: AI never writes anything directly to the ERP database.
ERP systems have hundreds of inter-table dependencies, business logic, and validations that the AI does not know about. A direct SQL write will sooner or later corrupt data integrity. The AI generates a decision proposal in JSON format, and a dedicated adapter executes it according to the system's rules.
Middleware as a Mandatory Traffic Buffer
ERP is not a system designed for thousands of requests per minute. It has maintenance windows, can block access under high load, and often runs on on-premise infrastructure that is several years old.
Middleware (n8n or a dedicated service) acts as a buffer and controller:
- Queues tasks — when 500 documents arrive simultaneously, the system will not collapse.
- Retries operations — when ERP is temporarily unavailable, tasks enter a retry queue with exponential backoff.
- Enforces idempotency — the same invoice will not be posted twice, even if the server restarts mid-operation.
- Separates AI and ERP worlds — middleware is the translator and gatekeeper simultaneously.
Without this layer, the integration works fine… until the first serious load spike.
AI Decision Contract — JSON as the Common Language of AI and ERP
The AI cannot return descriptive text like "this looks like a cost invoice". It must return a strictly defined data structure (JSON), validated against a schema before any write occurs. This decision contract makes the AI a predictable system component rather than a creative assistant.
{ "document_type": "invoice_purchase", "confidence": 0.97, "contractor_id": "CONT-10482", "amount_net": 4850.00, "amount_vat": 1115.50, "amount_gross": 5965.50, "currency": "PLN", "issue_date": "2026-04-22", "payment_due": "2026-05-22", "cost_account": "402-01", "decision": "auto_approve", "requires_human_review": false, "idempotency_key": "INV-2026-04-22-CONT10482-7d3f"}
Key contract fields:
- confidence — if below 0.85, the document automatically enters manual review regardless of other fields.
- cost_account — AI assigns the account from the chart of accounts using RAG (company knowledge), not from the model's general knowledge.
- decision: auto_approve / human_review — binary field determining the processing path.
- requires_human_review — flag overridden by business rules (e.g. amount exceeds authorisation threshold).
- idempotency_key — unique key that prevents double-posting even when the system restarts.
If the JSON structure is invalid or required fields are missing, the document enters the manual review queue. The system never writes "by force".
RAG and Company Context Memory
The AI does not make decisions based on knowledge from the internet. Before every decision it receives context from your company, delivered through RAG and a local vector database:
- Contractor history — has this supplier been problematic before? What are their typical amounts and payment timelines?
- Chart of accounts — the current accounting structure from your ERP, synchronised automatically.
- Discount and margin policy — thresholds at which a decision requires human approval.
- Previous similar cases — the AI learns from your approval and rejection history, improving decision accuracy over time.
This means the AI operates on your company's data rather than on assumptions and general accounting knowledge.
DEV / STAGE / PROD Environments
In accounting systems there is no room for experiments on a live database. A correct deployment requires three environments — and this is an element that is dramatically absent from most AI deployments.
| Environment | Database | Purpose | Who Has Access |
|---|---|---|---|
| DEV | Synthetic test data | Building logic, prompts, and adapters | Developer |
| STAGE | Anonymised copy of production | Testing on real data without risk | QA + client |
| PROD | Live ERP database | Production operations | Adapter API only |
I first build the logic and prompts in DEV. Then I test on a copy of the ERP database in STAGE — real data, no risk. Only when all edge cases pass does the solution move to production.
Failure Scenarios and Safeguards
This is where the difference between an "AI demo" and a production system becomes clear. Every scenario below must have a technical safeguard before the system goes live.
| Failure Scenario | Technical Safeguard |
|---|---|
| AI misreads invoice amount | Checksum + range validation + confidence threshold 0.85 |
| ERP API is unresponsive | Retry with exponential backoff + dead letter queue |
| Invoice in new, unknown format | Confidence below threshold → automatic human_review |
| Duplicate invoice on system restart | Idempotency key — second write blocked at middleware level |
| Amount exceeds authorisation threshold | Force: requires_human_review: true regardless of confidence |
We do not handle only the happy path — we handle every path.
Security and RBAC
Security in AI-ERP integration is a foundation, not an option:
- Principle of least privilege — AI has read-only access to selected data views (e.g. invoice view), never to the full database.
- Write only through the adapter — no API key has permission to write directly to the ERP SQL database.
- Key encryption — API keys and credentials stored in a secure vault (environment variables with encryption at rest).
- Full audit trail — every AI-executed operation is logged with timestamp, event source, and decision outcome.
- ERP never exposed to the internet — communication runs over VPN or a private network, never through a public endpoint.
For the IT department: full control, full accountability, zero black boxes.
Real Applications: Far More Than Invoice OCR
Once the Closed-Loop architecture is in place, the possibilities extend well beyond document recognition:
- Automatic replenishment orders — AI monitors inventory levels and places a supplier order when stock falls below the minimum threshold.
- Sales blocking on low margin — the system blocks invoice issuance when the calculated margin falls below a defined threshold — before the salesperson clicks send.
- Intelligent debt collection — AI analyses payment history and the tone of contractor correspondence, suggesting collection priority and communication style.
- Sales proposal generation — based on current stock, purchase prices, and margin policy, AI generates a client proposal without the salesperson's involvement.
- Automatic cost categorisation — every purchase is assigned to the correct accounting account without manual entry by the accountant.
- Cash flow forecasting — AI analyses payment history and open receivables to generate a weekly cash flow forecast.
Why Zapier and Make Are Not Suitable Here
Zapier and Make are excellent for marketing automations and simple integrations. In the ERP context they lack several critical elements:
- No transactional queues with delivery guarantees.
- No idempotency mechanism at the operation level.
- No advanced JSON schema validation before writes.
- No control over write logic — data enters without business-rule verification.
- Data passes through external servers (a GDPR concern for accounting data).
In ERP systems this is not a matter of convenience — it is a matter of data integrity and business security.
Summary: ERP Stops Being an Archive, Starts Being a Brain
AI integration with ERP is not another automation. It is building a decision layer over the company's transactional data.
ERP stops being a data archive — it becomes a source of decisions executed automatically, safely, and in line with the system's logic.
Every professional deployment requires the right integration method for the specific ERP, a middleware layer as buffer, a JSON Decision Contract as the communication language, RAG with company data, three test environments, and full RBAC.
If you are planning AI integration with your ERP system and want certainty that the architecture is correct from day one — I invite you to a consultation. We will start with an audit of your system and a map of the processes that AI can take over safely and effectively.
/// RELATED_RECORDS
How AI Reads Invoices from Email and Enters Them into ERP
AI can automatically read an invoice from an email attachment — PDF, scan, or phone photo — and enter the data directly into an ERP system without any manual retyping. Full automation of cost invoice processing: from the mailbox to accounting.
Where to Start with AI Implementation in Your Company
AI implementation starts not with choosing a tool, but with identifying one repetitive process that wastes the most human time. Learn step by step how to select, map, and automate that process.
How to Build a Company Internal Knowledge Base with AI (RAG in Practice)
An internal knowledge base built on RAG lets you create your own company chatbot that answers only from your company's documents — not the model's guesses. Safe, up-to-date, precise AI with full control over your data.
Signal received?
Terminate
Silence
Initiate protocol. Establish connection. Let's build something loud.