Architecting for AI
Architecting for AI means designing systems in which some behaviour is produced by machine learning models (today, mostly large language models) whose outputs are probabilistic, so that the system as a whole is still useful, safe, observable and affordable.
Start with the outcome
The first question isn’t “which model?” but “what problem are we solving, and how will we know it’s solved?” Be clear about the business value: which customer problem gets solved, which opportunity gets seized. Then ask whether the problem can tolerate a component that is sometimes wrong. Summarising, drafting, classifying, searching and extracting usually can, with the right checks. Calculating an invoice usually can’t, and doesn’t need to.
Don’t start with a model looking for a problem. Start with a problem, and a way to measure the answer.
AI and the mental model
The same mental model applies: start at the top and only drop down a level when you must.
- Service: pre-built AI APIs (translation, speech, document extraction) and hosted foundation models called through an API.
- Platform: managed model platforms such as Amazon Bedrock or Google Vertex AI, which offer a choice of models, managed retrieval, guardrails, evaluation and fine-tuning.
- Infrastructure: your own models on your own GPUs. Rarely the right starting point unless model ownership is your differentiation.
Building your own foundation model is the clearest possible example of building a commodity. Your advantage is in your data and your workflow, not in the model weights.
Common architectures
From simplest to most complex, and we recommend you climb only as far as you need:
- Prompt and call: a well-designed prompt sent to a model, with the response validated before use.
- Retrieval-augmented generation (RAG): retrieve relevant content from your own data (via search or vector indexes) and include it in the prompt, so answers are grounded in your information and can cite sources.
- Tool use: the model can call functions you define (look up an order, query a database) and use the results in its answer.
- Agents: the model decides which tools to call, in what order, in a loop, to pursue a goal.
- Fine-tuning: adapting a model to your domain. This is useful in specific cases, but it’s often reached for before simpler options have been exhausted.
The new non-functional requirements
AI adds dimensions to the architectural profile that traditional systems didn’t have:
- Answer quality: accuracy, relevance and groundedness. This needs measuring, not assuming.
- Safety: harmful content, off-topic use and leakage of sensitive data. Use guardrails on inputs and outputs.
- Security: prompt injection, where instructions hidden in user input or retrieved content subvert the system. Treat all model input as untrusted and limit what the model can do.
- Latency: generation is slow compared to a database query. Stream responses and design the user experience around it.
- Cost: token pricing scales with usage and prompt length. Track the cost per request as a unit cost, cache where you can and route simple tasks to smaller, cheaper models.
- Privacy and residency: know where prompts and data are processed and retained.
- Change: models are updated and retired. A model upgrade is a change to your system’s behaviour and needs testing like any other change.
Evaluation is testing
Because model outputs vary, you can’t test AI features with exact assertions alone. Evaluations (“evals”) are the equivalent of a test suite:
- a curated set of representative inputs with known good outputs or grading criteria
- automated scoring with rules, reference comparisons or a carefully checked model acting as a judge
- run on every change to prompts, retrieval, models or code, with thresholds that block a release
- complemented by monitoring in production: sampling real interactions, collecting user feedback and watching for drift
Evals are fitness functions for AI behaviour. Without them, every prompt tweak is a guess and every model upgrade is a gamble.
Treat AI work as complex
New AI features usually sit in the complex domain: cause and effect only become clear in hindsight. Big up-front design doesn’t work well here. Spike quickly, measure with evals, put something real in front of users early, and be prepared to stop. In a portfolio of AI experiments, stopping the ones that aren’t working is a success, not a failure.
The model is the most replaceable part of an AI system. Design so you can swap it.
Keep model calls behind your own interface, keep prompts and evals in version control, and make the choice of model a configuration setting rather than an architectural commitment.