Concepts / Modularity in AI Systems

Modularity in AI Systems

A high-level AI application architecture is a framework for understanding how components fit together, and the exact layout of any one application may differ from it.

  • Programming

Finding the Moving Parts of an AI Product

Imagine you are handed a finished AI product and asked where its moving parts are. You could start by guessing which piece handles the user's request, which piece calls the model, and which piece decides whether an answer is safe to show. Without a map, each guess stands alone, and you have no way to check whether one guess relates to another. This article gives you that map: a high-level architecture for applications built on top of foundation models.

The goal is not to memorize one fixed layout. The goal is to learn a way of thinking about how the pieces relate to each other, and what each new piece costs. This article belongs to a larger chapter on building applications on foundation models as a whole. Earlier material looked at individual aspects of AI engineering one at a time. This chapter shifts the lens: it asks how those individual aspects combine into a working application, and where things tend to go wrong along the way.

A Framework, Not a Fixed Blueprint

Definition

A high-level AI application architecture is a framework for understanding how components fit together, and the exact layout of any one application may differ from it.

The word framework matters here. A framework gives you a vocabulary and a set of questions to ask about any system, even when the system in front of you is organized differently from the common pattern. A blueprint, by contrast, would say exactly where every part goes. The architecture of a particular application may vary from the common pattern because teams make different choices about where work happens and which features they need.

What stays useful across every application is the shared way of reasoning. For any system you encounter, identify the components, identify how they connect, and identify what each one is responsible for. Those three questions work whether the system follows the common pattern closely or departs from it substantially.

The source builds this framework step by step. It walks through the construction of the architecture one stage at a time and, at each stage, discusses the challenges that appear and the techniques engineers can use to address them. This means you meet each component together with its typical problems, rather than as an abstract box on a diagram.

Tracing a Request Through Guardrail Checks

A guardrail is a check that constrains what the system accepts or produces. The easiest way to understand where guardrails sit is to follow a single request from start to finish. The diagram below shows one generic path: the request is checked before the model is called, the model produces a response, and that response is checked before it is returned. Trace each arrow and notice where the request can stop early.

User requestInput guardrail checkModel callOutput guardrailcheckAnswer returnedBlocked resultarrivespassesfailsresponsepassesfails
Where do guardrails sit relative to the model call, and what happens to a request when a guardrail blocks it versus when it passes?

Follow the two outcomes. If the input check fails, the request never reaches the model, so the blocked result is produced without a model call. If the input check passes, the model runs. If the output check then fails, the model has already produced a response, but that response is not shown to the user. In both cases the guardrail decides what the user finally receives. The diagram is a generic illustration of this control flow; the source itself does not prescribe a fixed number of checks or their order.

Worked example

Tracing a blocked request

A user submits a request to an AI assistant that has an input guardrail before the model call and an output guardrail after it. Trace what happens if the input guardrail flags the request.

  1. 1
    Request arrives

    The request enters the application and is handled first by the input guardrail check, before any model is involved.

  2. 2
    Input check fails

    The guardrail decides the request does not meet what the system accepts, so the request is stopped at this point.

  3. 3
    Model is skipped

    Because the request was stopped before the model call, the model is never invoked for this request.

  4. 4
    Blocked result returned

    The application returns a blocked result instead of an answer. The output check is never reached because there is no model output to check.

Result

The guardrail controlled the outcome without the model ever running. Had the input check passed, the path would have continued to the model call and then to the output check.

Why Components Overlap

Engineers separate components on purpose. Keeping responsibilities distinct makes a system easier to modify and maintain, because a change in one area is less likely to break another. That separation is the core idea behind modularity in AI systems.

The separation, however, is not rigid. Real systems do not divide into neat, non-overlapping slices. Several components can take on the same kind of job, and the boundary between two of them can blur. Modularity is therefore best understood as a useful guideline for drawing boundaries, not as a guarantee that every responsibility has exactly one home.

Guardrails are the clearest illustration. The source notes that guardrails can be implemented in the inference service, in the model gateway, or as a standalone component. The same kind of protection, in other words, has several legitimate homes. The diagram below shows that one piece of guardrail logic can be placed in any of these three components.

Guardrail logicInference serviceruns close to the modelModel gatewayshared entry for requestsand responsesStandalone componentseparate from bothcan be implemented incan be implemented incan be implemented as
Which components can take responsibility for the same goal, such as safety, and where do their boundaries intersect?

Read this diagram as a set of options rather than a single correct answer. The guardrail logic is the same in each case. What changes is which component is responsible for running it. Placing it inside the inference service keeps the check close to the model. Placing it in the model gateway puts it where requests and responses pass through a shared entry. A standalone component keeps it separate from both. The source does not rank these choices, so the decision depends on what the application needs.

Weighing a New Component

Adding a component is never free. The source states that each additional component can make a system more capable, safer, or faster. These are three different kinds of payoff, and a team might be chasing any one of them. But the same addition also increases the system's complexity and exposes it to new failure modes. Each gain comes bundled with a cost.

Question to askGain from the componentCost the component adds
Does it make the system more capable?New abilities the application did not have beforeMore parts to integrate and reason about
Does it make the system safer?Checks that constrain what is accepted or producedNew ways the check can fail or block legitimate requests
Does it make the system faster?Reduced time for some part of the workAnother moving part whose behavior affects overall timing

Each added component is weighed on its payoff against the complexity and failure modes it brings.

The practical lesson is that every component should justify itself. When you consider a new piece, ask which of the three gains it targets, and then ask what new failures it could introduce and how you would notice them. A component that adds capability but makes the system much harder to reason about may be a poor trade.

Observability Across the Pipeline

Monitoring and observability are described in the source as an integral part of any complex system. Observability is not a single tool. It has three connected parts: understanding how your system fails, designing metrics and alerts around those failures, and building the system so that failures can be detected and traced back to their source.

The diagram below shows where signals can be captured as a request moves through an AI application. Each stage the request passes through is a place where data about its behavior can be recorded and sent onward to a monitoring system.

User inputRetrieval stepwhere the application usesitModel callOutputMonitoring systemcaptured signalscaptured signalscaptured signalssent for monitoring
At which stages of a request can data be captured, and how does that data flow to a monitoring system?

Observability is partly a design decision made early. A system that was not built to expose the right signals will be hard to diagnose later, no matter what monitoring tool is attached at the end. This is why observability belongs in the architecture discussion rather than being an afterthought.

Many observability practices carry over from software engineering and from traditional machine learning. The source is clear, however, that foundation models introduce new failure modes. Those failures call for additional metrics and additional design considerations beyond what older practices provide.

Mistakes Teams Make With Modularity

  • Common mistake

    Treating the common architecture as a blueprint that every application must match exactly

    What it looks like

    A team rejects a working design because its guardrail is not in the place a reference diagram shows.

    Why it fails

    The architecture is a framework for reasoning about components. The exact layout of an application may differ, because teams make different choices about where work happens.

    Do this instead

    Ask the three framework questions: what are the components, how do they connect, and what is each one responsible for.

  • Common mistake

    Assuming each responsibility has exactly one home

    What it looks like

    A team assumes only the model gateway can enforce safety, so it never considers the inference service or a standalone component.

    Why it fails

    Components can overlap in function. Guardrails can be implemented in the inference service, the model gateway, or as a standalone component.

    Do this instead

    When a responsibility appears in several places, decide deliberately which component owns it and document the boundary.

  • Common mistake

    Adding a component because it sounds useful, without naming its gain

    Why it fails

    Each component can make a system more capable, safer, or faster, but it also increases complexity and introduces new failure modes.

    Do this instead

    Before adding a piece, state which of the three gains it targets and what new failures it could cause.

  • Common mistake

    Attaching monitoring at the end and expecting it to explain every failure

    What it looks like

    A team builds an application with no deliberate signals, then adds a monitoring tool after launch and finds it cannot trace failures to their source.

    Why it fails

    Observability is partly a design decision made early. A system not built to expose the right signals is hard to diagnose later.

    Do this instead

    Design the system to expose signals at each stage, and plan metrics and alerts around the failures you expect.

  • Common mistake

    Assuming traditional monitoring practices are enough for foundation models

Predicting Where a Guardrail Belongs

MEDIUM

A team is building an AI application and wants a safety check that constrains what the system accepts. Before reading further, decide which of these three homes you would choose first: the inference service, the model gateway, or a standalone component. Write down the one factor that drove your choice, then consider whether the source ranks these options.

Hints
  • Recall that the source says the same guardrail logic can live in any of the three homes; only the responsible component changes.
  • Think about whether the check should sit close to the model, at a shared entry point for requests and responses, or separate from both.
  • The source does not rank the options, so a good answer names a reason tied to what the application needs.
MEDIUM

Choose a new component you might add to an AI application. Name the single gain you are targeting (more capable, safer, or faster), then list one new failure mode it could introduce and one signal you would watch to notice that failure.

Hints
  • Use the three-part payoff from the source as your starting list.
  • A failure mode is a new way the system can go wrong because of the addition.

Reviewing the Map

  1. 1
    A high-level AI application architecture is a framework for reasoning about how components fit together; the exact layout of a given application may differ from it.
  2. 2
    Components in an AI system can overlap in function. Guardrails can live in the inference service, the model gateway, or as a standalone component.
  3. 3
    Each added component can make a system more capable, safer, or faster, but it also increases complexity and introduces new failure modes, so every component should justify itself.
  4. 4
    Observability is partly a design decision made early, and foundation models introduce failure modes that require additional metrics and design considerations beyond older practices.

Key Takeaways

  • A high-level AI application architecture is a framework for reasoning about how components fit together, not a fixed blueprint.
  • Guardrails illustrate overlap: the same check can be implemented in the inference service, the model gateway, or as a standalone component.
  • Every added component can make a system more capable, safer, or faster, but it also adds complexity and new failure modes.
  • Observability must be designed in early, and foundation models add failure modes that call for metrics beyond traditional practice.

Related concepts

More concepts starting with M