By the end of this lesson you will be able to:
- Explain LLMOps and how it differs from traditional MLOps.
- Walk through the lifecycle: ideate, build, evaluate, deploy, monitor.
- Build an evaluation set and compare prompt versions with metrics.
- Monitor quality, latency and cost in production.
Shipping is the start, not the finish
Our study buddy has chat, search, tools and safety layers. It works in demos. But real students ask things nobody imagined. Model providers release new versions. Prompts get tweaked. Costs creep up. Without a process, quality slowly drifts and nobody notices until the complaints arrive.
LLMOps is the set of practices for building, evaluating, deploying and improving LLM applications continuously, much as DevOps does for software and MLOps for machine-learning models.
MLOps vs LLMOps
Traditional MLOps
Train your own model on labelled data. Measure accuracy on a fixed test set. Retrain when the data drifts.
LLMOps
Usually start from a foundation model. Improve with prompts, RAG, tools and sometimes fine-tuning. Evaluate open-ended text for quality, groundedness and safety. Track tokens and cost.
The lifecycle, as a loop
The lifecycle is a cycle, not a straight line. Each pass finds new failures, turns them into test cases and fixes them. Run four improvement loops below and watch quality climb.
1. Ideate
Pick a real problem and define success before writing prompts. Collect 20–50 realistic example inputs with what a good answer looks like. This becomes your first evaluation set.
2. Build
Try prompts and models (Lessons 2, 4, 5), add RAG (Lesson 15) or tools (Lesson 11). Keep prompts in version control like code, so you know exactly what changed.
3. Evaluate
Run every version against the evaluation set and measure:
- Quality: is it correct and relevant? For RAG, is it grounded in the sources?
- Safety: harmful content, leaks, how well it resists your red-team prompts (Lesson 13).
- Latency: time to first token and total time.
- Cost: tokens per request, multiplied by your volume.
You can check answers with code (exact match, keywords, valid JSON), with human reviewers, or with another LLM acting as a judge with a clear scoring rubric. Tools like Azure AI Foundry's evaluation and prompt flow, LangSmith and promptfoo help run these at scale.
4. Deploy
Release gradually: first to a small group (or behind a feature flag), with content filters, rate limits, logging and a quick way to roll back.
5. Monitor
Track user feedback, errors, latency, token spend and flagged content. Sample real conversations (with privacy safeguards) to review. Every new failure becomes a test case, and the loop starts again.
Study-buddy example: teachers report that answers to Class 9 chemistry are sometimes too advanced. The team adds 30 Class 9 questions to the eval set with a "simple language" check, changes the prompt to state the student's class, and re-runs the evals. The score rises from 68% to 84% with no drop on other subjects. Then it ships to 10% of users, gets watched for a week, and rolls out to everyone.
Model updates count as changes. When a provider releases a new model version, run your evaluation set before switching. A "better" model can still behave differently on your task.
Hands-on
Your task: complete passes(). An answer passes when it contains all the required keywords (case-insensitive) and is at most max_words long. Then the script scores both prompt versions. Expected last line: Winner: v2.
eval_set = [
{"q": "What is photosynthesis?", "must": ["sunlight", "food"], "max_words": 40},
{"q": "Define speed.", "must": ["distance", "time"], "max_words": 30},
{"q": "What is an atom?", "must": ["smallest"], "max_words": 30},
]
answers = {
"v1": [
"Photosynthesis is a complex biochemical process involving chlorophyll, light-dependent reactions, the Calvin cycle and many enzymes working together inside the chloroplasts of plant cells to produce glucose and oxygen from carbon dioxide and water using sunlight.",
"Speed is distance travelled divided by time taken.",
"An atom is made of protons, neutrons and electrons.",
],
"v2": [
"Plants use sunlight, water and carbon dioxide to make their own food. That's photosynthesis!",
"Speed tells you how much distance something covers in a given time.",
"An atom is the smallest unit of an element.",
],
}
def passes(answer, case):
# TODO: True if every word in case["must"] appears in answer (ignore case)
# AND len(answer.split()) <= case["max_words"]
return False
scores = {}
for version, outs in answers.items():
ok = sum(passes(a, c) for a, c in zip(outs, eval_set))
scores[version] = ok / len(eval_set)
print(f"{version}: {ok}/{len(eval_set)} passed ({scores[version]:.0%})")
best = max(scores, key=scores.get)
print("Winner:", best if scores[best] > min(scores.values()) else "tie")
Show solution
def passes(answer, case):
text = answer.lower()
return all(word in text for word in case["must"]) and len(answer.split()) <= case["max_words"]
Your task: compute the median (p50) and 95th-percentile (p95) latency from today's requests, plus the total cost. If p95 is above 3.0 seconds, print the alert line. Use the nearest-rank method: sort the values and take the item at position ceil(p/100 × n), counting from 1.
import math
# (latency in seconds, tokens) for today's requests
requests = [(0.9, 420), (1.1, 380), (1.3, 510), (0.8, 300), (2.2, 900), (1.0, 450),
(4.8, 2100), (1.2, 470), (0.95, 400), (1.4, 600), (3.9, 1800), (1.05, 430),
(1.15, 460), (0.85, 350), (1.25, 520), (1.6, 700), (0.9, 410), (1.0, 440),
(2.8, 1300), (1.1, 480)]
PRICE_PER_1K_TOKENS = 0.002 # example price in dollars, not a real quote
def percentile(values, p):
# TODO: nearest-rank percentile: sort, then take index ceil(p / 100 * n) - 1
return 0.0
lat = [l for l, _ in requests]
p50, p95 = percentile(lat, 50), percentile(lat, 95)
cost = sum(t for _, t in requests) / 1000 * PRICE_PER_1K_TOKENS
print(f"Requests: {len(requests)} p50: {p50}s p95: {p95}s cost: ${cost:.4f}")
if p95 > 3.0:
print(f"ALERT: p95 latency {p95}s is above 3.0s")
else:
print("All good")
Show solution
def percentile(values, p):
ordered = sorted(values)
return ordered[math.ceil(p / 100 * len(ordered)) - 1]
Check your understanding
What should you build before tweaking prompts for a new feature?
- A marketing page
- An evaluation set of realistic inputs with what good answers look like
- A fine-tuned model
- A larger context window
Without an evaluation set you can't tell whether a change made things better or worse.
Your provider releases a new model version. What's the LLMOps way to switch?
- Switch immediately, newer is always better
- Never switch
- Run your evaluation set on it, compare, then roll out gradually
- Ask users to test it
Treat model updates like any change: evaluate, then deploy carefully.
A user reports a bad answer in production. What should happen next?
- Fix it and add that case to the evaluation set so it never comes back
- Delete the conversation
- Raise the temperature
- Ignore it, since it's only one report
Monitoring feeds the loop: real failures become permanent test cases.
Key takeaways
- LLMOps is a loop: ideate → build → evaluate → deploy → monitor → repeat.
- An evaluation set is your most valuable asset. Grow it with every failure.
- Measure quality, safety, latency and cost, using code, humans and LLM judges.
- Deploy gradually, monitor continuously, and re-evaluate when models change.
Next: Retrieval-Augmented Generation (RAG), so your app answers from your own documents.
Your progress is saved in this browser.
Adapted from Lesson 14 of Microsoft's "Generative AI for Beginners" (MIT License), rewritten and extended by Aiprojects4U. View source