AI application architecture
A reference architecture for LLM-powered apps: the request path, and how to handle latency, cost, hallucinations, security and evaluation.
Overview
Most production AI applications share the same shape. Understanding the request path helps you place the controls that keep the system fast, cheap, safe and accurate.
The request path
User
-> Application (auth, input validation, orchestration)
-> Retrieval / tools (search, databases, APIs)
-> AI model (inference)
-> Validation (schema checks, guardrails)
-> Response (with citations where relevant)
The application layer — not the model — is where you enforce identity, validate input, decide what context to retrieve, and check the output before returning it.
Latency
- Stream tokens so the user sees progress immediately.
- Cache repeated or deterministic results (see cache).
- Keep prompts lean; fewer tokens means faster inference.
Cost
- Cost scales with input + output tokens. Trim context, cap output length.
- Route simple requests to smaller/cheaper models; reserve large models for hard tasks.
- Use the AI ROI calculator to sanity-check the business case.
Hallucinations
- Ground answers with RAG and ask for citations.
- Validate structured output against a schema; reject and retry on failure.
- Let the model abstain when context is insufficient.
Security
- Treat all model input and tool output as untrusted (prompt injection is real).
- Never put secrets in prompts; keep them in the app/tooling layer.
- Apply least privilege to any tools the model can call. See agent security.
Observability & evaluation
- Log prompts, retrieved context, tool calls and outputs (minus sensitive data).
- Maintain an evaluation set and measure accuracy on every change.
- Track cost and latency per request as first-class metrics.
Related
Last verified: August 2026. Technology and pricing change — always confirm current details with the vendor.