AI ENGINEERING
Composite AI: Why Production AI Needs Deterministic Code Around LLMs
Prompting a model is not a system. How we combine deterministic software with probabilistic models to ship AI that a business can trust.
Most AI demos are a prompt and a model. Most AI failures in production are the same thing. The gap between the two is not a better prompt; it is software engineering. This essay explains the architecture we use at Sonder to close that gap, which we call Composite AI.
Definition: Composite AI wraps probabilistic models inside deterministic code. Hard-coded logic and orchestration enforce everything that must be predictable, and models such as LLMs or neural networks are used only where flexibility is genuinely required.
The problem with a raw LLM API
Language models are extraordinary at reading messy input. They are also probabilistic: the same input can produce different outputs, formats can break, and wrong answers arrive with the same confidence as right ones. If you pipe unpredictable inputs straight into a model and act on whatever comes back, you have built a system whose failure rate you do not know.
Mission-critical workflows need three things a model cannot guarantee on its own: output in an exact format, strict routing logic, and an auditable handoff layer that decides what happens next.
The three layers
1. The deterministic layer
Structured automation, orchestration engines and plain business logic. If data A arrives, it follows path B, every time. This layer owns validation, permissions, retries, logging and anything with a legal or financial consequence. There is no room for hallucination here, because there is no model here.
2. The probabilistic layer
Machine learning models and frontier LLMs, injected only where cognitive flexibility is required: interpreting unstructured documents, analysing images, or extracting intent from messy human input. The model’s job is narrow and its output is checked before anything acts on it.
3. The orchestrator
The orchestrator calls the probabilistic layer from inside the deterministic one. It validates every model response against a schema, applies confidence thresholds, and routes anything uncertain or high-risk to a human with full context.
intake(request)
-> classify_intent(llm) # probabilistic, narrow
-> validate(schema) # deterministic
-> if confidence < threshold or risk == "high":
escalate_to_human(context)
else:
route(rules[intent]) # deterministic
-> log(audit_trail)
Confidence thresholds and humans in the loop
A model that is right 94% of the time is wrong 6% of the time. The question is what happens to that 6%. In EdgeVision, our edge vision system for a renewable energy firm, predictions below a confidence threshold automatically go to a human reviewer queue. High-confidence cases flow straight through, so oversight stays meaningful without slowing everything down. Grad-CAM heatmaps show reviewers what the model was looking at, which is a large part of why engineers on site trusted it.
Shadow mode before autonomy
We never let a new system act on production on day one. Our delivery lifecycle builds the system in a hermetic sandbox on historical data, then runs it in shadow mode on live inputs while people review and approve every output. The AI cannot modify production systems until its accuracy consistently meets the agreed threshold. By then, the business has evidence rather than a promise.
Sometimes the right model is not an LLM
Composite AI also means choosing the smallest model that does the job. EdgeVision replaced a slow, costly cloud workflow built on GPT-4o with a compact ResNet-18 model fine-tuned on the client’s own images. It runs fully offline, reaches 94% accuracy across 56 repair stages, and cut inspection time from four hours to under a second. A frontier model would have been more impressive in a demo and worse in the field.
Monitoring is part of the architecture
Production AI degrades quietly. Inputs drift, products change, and accuracy slips without anyone noticing. The deterministic layer is where monitoring lives: logging every input and output, tracking accuracy and drift, versioning prompts and models, and alerting a human before customers notice. This is the MLOps and LLMOps work that separates a system from a script.
A checklist for production AI
- Every model output is validated against a schema before anything acts on it.
- Routing and permissions live in code, not in a prompt.
- Low-confidence or high-risk cases escalate to a named human role.
- The system ran in shadow mode on real data before it was allowed to act.
- Accuracy, drift and cost are monitored, with alerts.
- The smallest model that meets the accuracy target is the one in production.
Composite AI is how we approach every AI strategy and production AI build. If you have a workflow that needs AI but cannot tolerate surprises, bring it to us.
Frequently asked questions
What is Composite AI?
Composite AI is an architecture that wraps probabilistic models, such as LLMs and neural networks, inside deterministic software. Hard-coded logic enforces routing, formats and business rules, and models are used only where judgement or flexibility is needed.
Why not just call an LLM API directly?
Because LLM output is probabilistic. The same input can produce different outputs, formats can break and answers can be confidently wrong. Mission-critical workflows need guaranteed formats, strict routing and an auditable handoff layer that a model cannot provide on its own.
Do production AI systems always need an LLM?
No. Many problems are better solved with smaller, specialised models or plain code. In EdgeVision, a compact ResNet-18 model replaced a slower cloud workflow built on GPT-4o and runs fully offline in under a second.