How to deploy an LLM in production
By Abdul Asim ·
The short answer
To deploy an LLM in production, treat the model as one component inside a normal service: put it behind a gateway, version the prompt, model and config together, validate what goes in and what comes out, block releases that fail an evaluation set, log every request, and ship changes to a small slice of traffic first so you can roll back. Then decide in advance which actions a human must approve.
The model call is usually the easy part. What makes an LLM in production reliable is everything around it, and that is what this guide covers, whether you are shipping a chatbot, an internal assistant, an agent that calls tools, or a document workflow.
Choose the model setup: hosted API or self-hosted
Most teams should start on a hosted API. You get the strongest models, no GPU operations, and you can switch providers behind a gateway later. Self-hosting an open-weight model earns its place when data cannot leave your network, when volume is high and steady enough that owning the hardware is cheaper, or when you need a small model tuned to one narrow task.
| Question | Hosted API | Self-hosted open-weight |
|---|---|---|
| Time to first release | Days | Weeks, plus serving and scaling work |
| Data residency | Depends on the provider's terms and region | Stays inside your infrastructure |
| Cost shape | Pay per token, scales with usage | Fixed GPU cost, cheaper only at steady high volume |
| Model quality ceiling | Highest available | Lower for general tasks, can match on narrow ones |
| Who handles upgrades | Provider, sometimes on their schedule | You, on your schedule |
Fine-tuning is a separate decision. Reach for it when prompting and retrieval cannot get the format, tone or classification accuracy you need, not as a way to add knowledge. The fine-tuning guide covers when it pays off. If the problem is that the model does not know your documents, you want retrieval: see how to build a RAG pipeline.
The architecture around the model
Every LLM deployment I ship has the same few layers, whatever the use case: - A gateway. One internal service that every model call goes through. It holds API keys, applies rate limits and timeouts, retries on provider errors, falls back to a second model when the first is down, and writes the request log. Application code never calls a provider directly. - Prompt and config management. Prompts live in version control or a config store with an ID, not as strings scattered through the code. Each release pins a prompt version, a model version and the settings (temperature, max tokens, tool list). - Tools with narrow permissions. If the model can call functions, each tool does one thing, validates its own arguments, and only has the access that one thing needs. - Retrieval, if the answer depends on your data. A search step that supplies the relevant passages. The RAG pipeline guide explains how that layer fails and how to harden it.
On the McKissock AI sales assistant, the model answers product questions from retrieved company knowledge, and when it cannot resolve a request it calls a dedicated ticket-creation tool that opens a HubSpot ticket. That tool is the whole escalation path, which keeps it simple to test and simple to audit.
Set latency and cost budgets before launch
Write two numbers down per task before you pick a model: how long a user will wait, and what one completed task may cost. Without them, every choice below is a guess.
For latency, measure time to first token separately from total response time. In a chat interface, streaming the answer token by token makes a ten-second response feel usable, because the user starts reading in under a second. For a background job that returns JSON, streaming does not help and total time is what matters. Long, stable system prompts are a good candidate for provider-side prompt caching: Anthropic's prompt caching documentation says reusing a cached prefix reduces processing time and cost and generally improves time to first token on long inputs. Caching whole answers is riskier. Only reuse a stored answer when the input is exactly the same and the answer cannot have gone stale.
For cost, count tokens per completed task, not per call. An agent that loops through five tool calls and re-sends the full history each time can cost several times what a single-call design costs. The levers that work: route simple requests to a smaller model and keep the large model for hard ones, trim conversation history, cap the number of agent steps, and set a hard max-tokens limit on every call. OWASP lists runaway usage as its own risk, LLM10:2025 Unbounded Consumption, so put per-user and per-tenant limits in the gateway from day one.
Guardrails: validate what goes in and what comes out
Treat model output as untrusted input to the rest of your system. That one rule covers most of what guardrails need to do. - Input checks. Length limits, file type checks, removing or masking personal data you do not need to send, and refusing requests that are clearly out of scope. - Structured output. When code consumes the response, ask for JSON against a schema and validate it. OpenAI's Structured Outputs guide constrains completed, non-refusal output to your schema, which still leaves refusals, truncated responses and business rules for you to check. - Business-rule checks. A valid schema says the shape is right, not that the content is. Check numbers against limits, IDs against your database, and dates against the calendar. - Prompt injection defenses. Any text the model reads from users, documents, web pages or tool results can carry instructions. Limit what tools can do, keep secrets out of prompts, and require approval for anything irreversible. The prompt injection guide goes deeper, and the OWASP Top 10 for LLM Applications 2025 is the checklist I review against.
Some values should never come from the model at all. On the MavenIT quoting workflow, prices are calculated by defined pricing rules from matched historical quotes and structured equipment and contract data. The model helps with matching and drafting, but it does not produce the number, and cases without a suitable match go to a person instead of getting an invented estimate.
Gate every release on an evaluation set
Before any change ships, whether a new prompt, a new model version or a new tool, run it against a fixed set of real inputs with written pass rules and compare the score with the current release. If the score drops on a category that matters, the change waits. This is the single habit that separates a stable LLM deployment from one that silently gets worse every few weeks.
Include the cases that hurt: requests with no valid answer, hostile inputs, long inputs near your token limits, and the top tasks by volume. Provider model upgrades count as a change too, so pin model versions and re-run the set before moving. The LLM evaluation guide explains how to build the set and choose pass criteria.
What to log for every request
When a user reports a bad answer, you need to rebuild exactly what happened. Log, per request: - request ID, user or tenant ID, and timestamp - the release identifier: prompt version, model name and version, config version - the full input after preprocessing, retrieved passages or their IDs, and tool calls with arguments and results - the output, whether it passed validation, and any guardrail that fired - input and output token counts, cost, time to first token and total latency - the outcome: answered, refused, escalated, or user feedback
On McKissock, requests are sent to New Relic so the assistant can be watched outside the chat window, alongside the HubSpot tickets that show where it handed off. Decide early how long you keep this data and who can read it, because these logs contain whatever users typed. The AI governance guide covers who owns those decisions.
Release safely: shadow, canary, rollback
A prompt change is a code change, so ship it like one. Bundle the prompt, model and config into one versioned release, so rolling back means switching one identifier rather than reverting three things by hand.
- Shadow. Run the new release on a copy of live traffic without showing its output to users, and compare it with the current release on cost, latency and validation failures.
- Canary. Send a small share of real traffic to the new release. Google's SRE workbook describes canarying as a partial and time-limited deployment of a change together with its evaluation, which is the right framing: the canary is only useful if you watch the numbers while it runs.
- Widen or roll back. Widen in steps when error rate, escalation rate, cost per task and feedback hold steady. Roll back the moment one of them moves the wrong way, then add the failing cases to the evaluation set.
Human escalation and approvals for risky actions
Decide which actions the system may take alone and which need a person, and enforce it in code rather than in the prompt. Answering a question can run unattended. Sending an email to a customer, changing a record, spending money or running a test against a live system usually should not.
Two patterns from my projects. On the Center for Creative Leadership reporting workflow, source data is validated before drafting, the generated analysis is validated again after drafting, and team leads approve each report through Outlook before it is distributed. On the Odva agentic security testing workflow, the agent plans tests inside an authorized scope, risky proposed tests go to a human reviewer, and findings are validated against a Pydantic schema and stored with evidence. In both, the model drafts and proposes; a person owns the decision that carries risk.
Pre-launch checklist
- Latency and cost budgets written down per task, and measured against them
- All model calls go through a gateway with timeouts, retries, a fallback model and per-tenant limits
- Prompt, model and config versioned together as one release
- Inputs checked, outputs validated against a schema and business rules
- Tools scoped to minimum permissions, irreversible actions behind human approval
- Evaluation set passes, including hostile and no-answer cases
- Every request logged with release ID, tokens, cost, latency and outcome
- Shadow or canary plan agreed, with a tested one-step rollback
- A clear handoff to a human when the system cannot help
If you already have an LLM application live and want an outside read on it against this list, an AI app review is built for that. If you are starting from scratch and want it designed with these controls from the first release, see custom AI and agentic systems. Teams moving a retrieval-heavy pilot into production should also look at the RAG-specific stage gates in building RAG applications for production.
