"Systems, not prompts: the architecture of an AI feature that doesn't fall over"
When an AI feature misbehaves, the reflex is to open the prompt file. But the prompt is one component in what should be a system. A walk through the architecture that has to exist around the model call: input validation, orchestration that owns state, tool boundaries, output schemas, fallbacks and traces.

When your AI feature misbehaves, what does your team actually do? In most companies I talk to, the answer is: someone opens the prompt file, adds a paragraph in capital letters telling the model to please stop doing the bad thing, redeploys, and watches. Sometimes it helps. Usually it helps until next week, when the model finds a new way to misbehave that the paragraph did not anticipate, and the cycle repeats.
The problem is not that prompt changes are useless, wording genuinely matters. The problem is the mental model behind the reflex. Prompt-tweaking culture treats the model as the system. Production engineering treats it as one component in the system: remarkably useful, non-deterministic, occasionally wrong with total confidence, and subject to change without notice by the company hosting it. Framed that way, the question stops being "how do I write the perfect prompt" and becomes "what has to exist around the model call so that an imperfect answer doesn't take the feature down". That question has a standard enough answer to be worth walking through.
Start before the model is ever involved. Raw production input is hostile: emails with fourteen levels of quoted history, PDFs where the text layer is garbage, user messages that are empty or in the wrong language or forty pages long. Every one of those should be caught, normalised, or rejected by ordinary code before a single token is spent. A surprising share of "the model got it wrong" incidents are actually "we fed the model something no one would have got right", and that is an input validation bug wearing an AI costume.

Next, orchestration. Something has to own state: which step of the workflow this is, what has already been tried, what context the model should see this time. That something should be code, a LangGraph graph, an n8n workflow, a plain state machine, not the model's own memory of the conversation. Anthropic's engineering guidance draws a useful line here between workflows, where code steers the model through predefined paths, and agents, where the model directs its own process, and recommends the simplest pattern that works. Most production features are workflows, and should be. When code owns state, a failed step can be retried with the same inputs, a stuck run can be inspected, and the model sees exactly the context you chose. When the model owns state, you have a system whose behaviour you can neither reproduce nor explain.
Tool use deserves its own hard boundary, and the rule is simple: the model requests, code decides. If an agent can send emails, the model outputs a structured request to send an email, and deterministic code checks it, is this recipient allowed, is this the third attempt, is this action reversible, before anything happens. OWASP's Top 10 for LLM applications has a name for what happens otherwise, excessive agency, and its prescribed fix is exactly this: enforce authorisation in the downstream systems, never in the model. Skip that, wire the model's output straight to the trigger, and it works right up until the day it hallucinates a tool call, and then you are explaining to a customer why an AI emailed them at 3am.
On the way out, the same scepticism applies. Every model output gets validated against a schema, Zod, Pydantic, whatever fits your stack, before downstream code touches it. Some providers now enforce output schemas at generation time, which helps, but constrained decoding guarantees shape, not sense: a syntactically valid answer can still be wrong, so range and sanity checks stay in your code. A failure at this boundary is a bounded retry, not an exception in some unrelated service twenty minutes later. In extraction work I go further and attach per-field confidence, the approach behind my open-source docextract (github.com/afareed007/docextract), so a result can be 90% usable and 10% flagged rather than accepted or discarded wholesale.
Then the paths nobody demos: what happens when the model is wrong and validation cannot prove it. A confidence threshold that routes low-certainty results to a human review queue. A fallback to a simpler model or a rule-based default when the provider is down. An escalation path that says "I don't know" honestly instead of guessing fluently. These are not edge-case decoration, over months of operation, they are load-bearing.
And wrapped around all of it, observability. Every model call traced with its inputs, outputs, latency and cost, Langfuse does this well, so that when behaviour drifts, you can see what changed and when, rather than staring at a prompt file wondering. With traces, "the model got weird on Tuesday" becomes a diff you can actually look at; without them, every incident investigation starts from zero.
Here is the honest part: this is more work than tweaking a prompt, and there is no shortcut that makes it not so. But notice what the work is. Validation, state machines, permission checks, schemas, fallbacks, tracing, none of it is exotic AI research. It is the ordinary discipline of building around an unreliable dependency, which software engineers have been doing for decades. That is also why, when I mentor developers moving into AI work, we spend far more time on architecture than on wording. The teams whose AI features hold up are not the ones with the cleverest prompts. They are the ones who stopped expecting the prompt to be the system.
Designing and building this architecture, for AI features that have to survive contact with production, is exactly the work I do. If yours is stuck in the tweak-and-hope cycle, get in touch via the contact form.
Senior engineering roles — or production AI consulting?
I'm open to senior AI and software engineering roles and to selective consulting on agents, RAG, and LLM automation in production. If this post resonates — as a hiring manager or as someone shipping similar work — get in touch.
Get in touch