DEV Community

Cover image for AI Agents Should Not Touch Your ERP Directly. Build an Execution Layer Instead.
Muhammad Gharis
Muhammad Gharis

Posted on

AI Agents Should Not Touch Your ERP Directly. Build an Execution Layer Instead.

tags: ai, n8n, fastapi, architecture

Everyone is building AI agents right now.

That is not the hard part anymore.

Writing a Python script that calls an LLM is simple. You can connect an API, send a prompt, receive a response, and call it an agent.

The real problem starts when that agent wants to do something useful inside a business system.

Update inventory.

Create a vendor payment.

Change a CRM record.

Post a transaction.

Trigger a customer notification.

Touch an ERP database.

That is where many AI agent demos become dangerous.

Because a raw LLM is probabilistic.

Enterprise execution needs control.

The problem

Most AI agent examples look clean in a demo.

A user asks something.

The agent understands it.

The agent calls a tool.

The system updates something.

Done.

But in a real ERP or backend environment, that is not enough.

Before an AI-generated action reaches a production system, you need answers to basic questions:

Who approved this action?

Was the payload validated?

Was the user allowed to perform this operation?

Was the vendor active?

Was the amount above the approval threshold?

Was the inventory update within allowed limits?

Was the final API request deterministic?

Was every step logged?

Who owns the failure if the action is wrong?

This is the gap between an AI experiment and an AI-enabled business workflow.

Why direct AI-to-ERP execution is risky

An AI agent should not directly write into an ERP system.

Not because AI is useless.

Because ERP systems contain business-critical data.

They contain customers, invoices, vendors, payments, inventory, payroll, approvals, and financial records.

If an AI agent sends the wrong payload, chooses the wrong record, or skips a business rule, the damage is not theoretical.

It can affect reporting, operations, finance, compliance, and customer trust.

That is why I do not like the pattern where an LLM directly controls execution.

The LLM should help with reasoning.

It should extract intent.

It should summarize context.

It should classify requests.

It should draft responses.

But execution should be handled by deterministic systems.

A better pattern: AI execution layer

The safer architecture is:

Webhook request
→ AI extraction
→ Schema validation
→ Guardrail decision
→ Human approval if needed
→ ERP/API execution
→ Audit log
Enter fullscreen mode Exit fullscreen mode

This separates reasoning from execution.

The AI does not directly update the ERP.

Instead, it produces structured output.

That output is validated.

Then business rules decide whether the action is allowed, blocked, or requires human approval.

Only after that does the workflow call the ERP or backend API.

Where low-code orchestration helps

This is where tools like n8n become useful.

Not because low-code replaces backend engineering.

It does not.

You still need Python, FastAPI, Django, APIs, validation models, databases, and proper infrastructure.

But low-code orchestration gives you a visible execution layer.

You can see the workflow.

You can see routing logic.

You can add approval checkpoints.

You can separate AI reasoning from API execution.

You can log every decision.

You can make the process easier for business and technical teams to review.

That visibility matters when AI starts touching real systems.

Example architecture

A practical setup could look like this:

n8n Webhook
    ↓
FastAPI AI Extraction Service
    ↓
Pydantic Schema Validation
    ↓
Guardrail Evaluation
    ↓
Decision:
    - Allow
    - Require Approval
    - Block
    ↓
Mock ERP / Real ERP API
    ↓
Audit Log
Enter fullscreen mode Exit fullscreen mode

In this architecture:

  • FastAPI handles the backend service layer.
  • Pydantic enforces strict schemas.
  • n8n handles orchestration and approval routing.
  • The ERP API only receives validated requests.
  • Every decision is logged.

The AI is useful, but it is not trusted blindly.

Demo scenario

I created a small demo concept around two common ERP-style workflows:

  1. Low-risk inventory update
  2. High-risk vendor payment

The inventory update can proceed if it passes validation and stays within allowed limits.

The vendor payment requires human approval if the amount crosses a defined threshold.

Invalid or incomplete requests are blocked before they reach the ERP layer.

For example:

{
  "request_text": "Increase inventory for item SKU-1001 by 25 units in warehouse WH-01",
  "source": "webhook",
  "requested_by": "operations_user"
}
Enter fullscreen mode Exit fullscreen mode

The AI extraction service converts this into structured intent.

Then validation checks the required fields.

Then guardrails decide whether the action can continue.

Only then does the mock ERP endpoint receive the request.

What the guardrails check

Some simple example rules:

  • Vendor payment above 10,000 requires approval.
  • Missing vendor ID fails validation.
  • Inventory update above 500 units requires approval.
  • Unknown action type is blocked.
  • Low confidence AI extraction requires human review.
  • Payment to inactive vendor is blocked.

These rules are not complex.

That is the point.

The execution layer should be predictable.

The LLM should not be responsible for deciding every business rule at runtime.

Why audit logs matter

If AI is involved in business execution, audit logs are not optional.

You need to know:

  • What request came in
  • What the AI extracted
  • What validation returned
  • Which guardrail decision was made
  • Whether approval was required
  • Who approved it
  • What ERP action was executed
  • What response came back

Without this, you do not have an AI workflow.

You have an invisible automation risk.

What this demo is not

This is not a production ERP connector.

It does not claim to solve compliance by itself.

It does not replace authentication, RBAC, rate limits, secret management, monitoring, or proper security review.

Self-hosting also does not automatically make a system compliant.

Compliance depends on implementation, hosting, contracts, access control, logging, data handling, and internal policy.

The goal of the demo is simpler:

Show the architecture pattern.

AI for reasoning.

Deterministic systems for execution.

Orchestration for visibility.

Approval for high-risk actions.

Audit logs for accountability.

Why this matters for ERP systems

This pattern applies well to environments like:

  • Odoo
  • Oracle
  • Django/FastAPI business systems
  • Internal admin portals
  • Finance workflows
  • Inventory workflows
  • CRM automation
  • Support ticket routing
  • Vendor and invoice processing

The more critical the system, the more important the handoff design becomes.

The main question is not:

Which LLM should we use?

The better question is:

Where does the AI stop, and where does controlled execution begin?

GitHub demo

I am preparing a small reference repo for this pattern:

https://github.com/gharisj3/ai-agent-execution-layer-demo
Enter fullscreen mode Exit fullscreen mode

The repo structure includes:

  • FastAPI backend
  • Mock ERP endpoints
  • Pydantic validation
  • Guardrail rules
  • Audit log storage
  • n8n workflow export
  • Sample payloads
  • Demo script
  • Security notes

The demo flow is:

Webhook request → AI extraction → schema validation → guardrail decision → human approval if needed → mock ERP execution → audit log
Enter fullscreen mode Exit fullscreen mode

Final thought

AI agents will become more useful inside business systems.

But they should not be allowed to operate like invisible admin users.

The future is not one chatbot controlling everything.

The better direction is controlled execution layers, clear permissions, validation rules, approval checkpoints, and audit trails.

That is where AI becomes useful for real operations.

Not because it can generate text.

Because it can support business workflows without bypassing the controls those workflows require.

If you are exploring this pattern for Odoo, Oracle, Django/FastAPI backends, or n8n-based automation, I am happy to discuss how it can be adapted to your environment.

Top comments (0)