TecnoStack
Start a projectالعربية
A legacy core block stays untouched while a separate adapter service beside it is the only part that reaches the model.
AI engineering

Add an LLM to a legacy application without opening up the core: an adapter service beside it, the signed-in user's identity, a few typed tools, and a write path that waits for your business rules and a person's confirmation.

In this article

Silent video with on-screen text. The transcript below repeats every screen and describes what it shows.

Watch on the video page

  1. 0:00–0:06

    Build beside the core • Legacy core unchanged • Adapter beside it • Support screen • Legacy core • Adapter service

    The Support screen badge stays fixed at the top. The heavy Legacy core block stands unchanged; the Adapter service case slides in beside it and one narrow cyan line joins the core to the adapter; then a second line runs from the adapter to a plain unlabelled sphere that stands for the model. Nothing connects the sphere to the core.

  2. 0:06–0:12

    One task, one checked call • Only the ticket ID • Screen as before on failure • Support screen • Ticket ID • Adapter service • Checked summary • Typed failure

    The task-shaped call figure enters: a Ticket ID token, the Adapter service case and two possible exits, Checked summary and Typed failure. A cyan trace runs from the ticket into the adapter, lights its three blank steps in order and stops at the fork; neither dashed exit lights.

  3. 0:12–0:18

    Act as the signed-in user • Identity from the server • No shared admin account • Support screen • Legacy core • Adapter service

    The Legacy core and the Adapter service case stand apart. Three data calls leave the adapter for the core one after another, each carrying a small blank identity tag. A separate blank card standing for a shared admin account fades; no line ever reaches it.

  4. 0:18–0:24

    Give only small typed tools • Read-only by default • Mapped to business APIs • Support screen • Legacy core • Adapter service

    Three small blank tool tiles leave the Adapter service case one after another and snap into three existing API sockets beside the Legacy core. A wide generic tile is set aside and fades; it never connects.

  5. 0:24–0:30

    Writes wait for confirmation • Rules validate first • Nothing saved yet • Support screen • Refund draft • Legacy rules • Support agent confirms • Existing API

    The refund write-path figure enters: Refund draft, Legacy rules, Support agent confirms and Existing API. A cyan highlight lifts the blank sheet from the Refund draft station, carries it to Legacy rules and stops there; the routes on to Support agent confirms and Existing API stay dashed, so nothing is saved.

To add an LLM to a legacy application, put the model behind a separate adapter service and leave the legacy core in charge. The adapter acts with the signed-in user's identity, offers the model a few typed tools, reads only what that user may see, and proposes changes that your existing business rules validate before anything is saved.

Below you will find what to build and where each boundary sits. The order of work, from the first pilot to a full release, belongs in a staged LLM rollout plan for legacy software.

The reference architecture has five parts, and only one of them is new code that talks to the model. The legacy core keeps its database, rules and release process, while the adapter service owns everything that changes when prompts or models change.

PartWhat it ownsWhat it never does
Legacy coreRecords, business rules, its release processCall the model directly
Adapter servicePrompts, model calls, tool definitions, output checks, AI logsHold an administrator account or write to the database
Model endpointText generation, hosted or self-hostedReceive requests from anything except the adapter
Read sidePermission-filtered APIs, a constrained read replica or a retrieval indexChange a record
Write sideThe application's existing business APIsAccept a change that skipped validation or confirmation

The split follows from one fact: prompts, model versions and output checks change on a different schedule from legacy code. When they all live in the adapter, the legacy release train carries no AI changes, and switching a feature off is a configuration change.

Putting the LLM beside the core keeps every AI change out of code your team is afraid to touch. A wrong prompt or a slow model then breaks one feature, and the screens, transactions and reports that already work stay as they are.

The seam borrows from the strangler fig pattern. AWS Prescriptive Guidance describes it as replacing a monolith one component at a time, with a proxy layer routing each request to the old or the new system, and an anti-corruption layer that "works as an adapter or a facade" between them. Our goal is narrower: we add a capability and leave the system in place. The adapter does the same job as that facade, and if you later replace parts of the core, the seam is already there.

The AI adapter service turns one business task into one model call with checked output. The legacy application calls task-shaped endpoints, never a generic "send this prompt" endpoint.

A support screen, for example, calls a summarise-ticket endpoint with only a ticket ID. The adapter then:

  1. Fetches the ticket through the read side, as the signed-in user.
  2. Builds the prompt from a versioned template.
  3. Calls the model with a timeout.
  4. Checks the output against a schema.
  5. Returns a typed result: a summary that references the messages it used, or a typed failure.

Plan for failure from the first call. When the adapter is slow, down or returns output that fails validation, the legacy screen behaves as it did before the feature existed. Keep model calls out of transactions that must not fail, such as checkout or payment posting, and put long jobs, such as summarising large documents, on a queue whose results appear when ready.

Prompt templates, model versions, tool lists, limits and feature flags live in the adapter under version control and review, so nobody hunts for them in legacy code.

A Ticket ID token enters the Adapter service, which has two possible exits, Checked summary and Typed failure, with neither selected.

Illustrative support example: the legacy screen sends only a ticket ID. The adapter fetches the ticket as the signed-in user, calls the model and checks the output, then returns either a checked summary or a typed failure. On failure the screen works as it did before.

The model acts as the signed-in user, and the adapter learns who that is from your server, never from the prompt. The legacy application passes the authenticated user as a short-lived signed token, or a gateway attaches it, and the adapter forwards that identity on every data call.

The same rules that govern the legacy screen then check every read. Do not give the assistant one powerful service account: with a shared administrator account, someone can talk the model into requesting records the user could never open. Nothing in a question, a retrieved document or a tool result may change identity, so a message claiming to come from an administrator changes nothing.

Background jobs without a user, such as overnight summaries, get their own service identity, limited to that job's data and logged separately. Document search follows the same rule at the index, which is how permission-aware retrieval for company documents works: filter by permission before any passage reaches the model.

Give the LLM only small, typed tools that map to business APIs you already trust. Most legacy features need no tools at all: the code fetches the record, and the model summarises, classifies or drafts.

Anthropic's engineering guide to building effective agents separates workflows, where code runs "predefined code paths", from agents, where the model directs its own tool use, and recommends "finding the simplest solution possible". Whether a feature needs more autonomy is a business decision first; our CTO guide to when an agent is worth it helps you make it.

OWASP's Top 10 for LLM Applications (2025 edition) lists excessive agency as a risk, caused by excessive functionality, permissions or autonomy. Its mitigations match this design: minimise tools, minimise their permissions, run them in the user's context and require user approval. In practice, each tool is:

  • Narrow and typed. get_order_status(order_id), never "run SQL" or "fetch any URL".
  • Mapped to an existing business API, reusing its validation and permission checks.
  • Read-only by default. A tool that would change data returns a proposal for a person to confirm.
  • Bounded by allowlists, rate limits and input validation, as any untrusted request would be.

The same OWASP list puts prompt injection first. Treat tool results and retrieved text as data, never as instructions: a record containing "ignore previous instructions" must not trigger another tool or widen access.

Reads and writes take different paths, and the model never commits a change itself. The read path answers questions within the user's permissions; the write path turns a model's draft into a change only after validation and confirmation.

Read-only access still needs care. It can expose sensitive information, and a wrong answer can lead someone to a bad decision, so permission checks, testing and source references stay on the read path too. For reporting questions, expose a fixed set of views on a read replica, never free-form SQL on production.

On the write path:

  1. The model produces a structured proposal.
  2. The legacy application validates it with the same rules as a manual entry.
  3. The user sees what will change, line by line, and confirms.
  4. The existing API commits it under the user's identity, with an idempotency key so a retry cannot apply it twice.
  5. The audit record notes that the assistant drafted the change and who approved it.

An illustrative example: a support agent asks the assistant to refund a damaged item. The assistant reads the order and the refund policy through read-only tools, then drafts a refund request with the amount, reason and policy reference. The legacy refund service validates it as it would a manual request, the agent confirms, and the refund posts under the agent's account. If validation fails, the draft comes back with the reason and nothing has changed.

A Refund draft moves to Legacy rules; the stations Support agent confirms and Existing API wait ahead on a dashed route, so nothing is saved.

Illustrative refund example from the article: the model drafts a refund request, the legacy refund rules validate it as they would a manual entry, the support agent confirms the change, and only then does the existing API commit it under the agent’s identity. Here the draft has not been saved.

Every LLM feature needs a trace, a test set, a spending limit and its own off switch before real users see it. These controls sit in the adapter, so none of them waits for a legacy release.

  • Trace every request with one correlation ID across the legacy screen, adapter, model and tool calls.
  • Log what a review needs: the user, prompt and model versions, tool calls, record IDs, output and validation result. Restrict access to these logs, set retention limits and redact sensitive fields.
  • Set limits on requests and spend per user and per feature, so a runaway loop stops at the limit.
  • Keep a kill switch per feature, independent of legacy releases.
  • Test before every change to prompts, models or tools, with cases for correct answers, refusals, permission boundaries and injection attempts. Start by measuring groundedness with labelled examples, then decide what must pass with release gates for LLM features.

Each of these shortcuts lets the model into your core, and each has a direct replacement.

ShortcutWhat goes wrongDo this instead
Calling the model from the browser or mobile app clientThe API key ships to every userCall the adapter from your server
A generic SQL or HTTP tool "for flexibility"One injected instruction can read or change anythingNarrow, typed tools on business APIs
One shared administrator accountAny prompt can escalate privilegesThe signed-in user's identity on every call
A synchronous model call inside a critical transactionA slow model blocks checkout or paymentsA queue, or a call outside the transaction
Model output written straight to recordsUnvalidated changes reach your system of recordA proposal, validation and user confirmation

Start with one task-shaped feature on the read path, add typed tools and the write path only when a feature needs them, and keep the identity rule fixed throughout. Before you write code, check five things: the adapter is the only caller of the model, every data call carries the user's identity, every tool maps to an existing business API, every write waits for confirmation, and each feature has its own off switch.

If you want a second pair of eyes on these boundaries in your own system, our team offers custom AI development that starts with an architecture review of your application.

The architecture and recommendations in this article are TecnoStack's engineering guidance, not requirements set by AWS, Anthropic or OWASP. Sources checked in October 2026.

Discuss your website, store, app or AI project in Arabic or English. We agree the scope before work starts.

Book a free scoping callCompare services and prices