Trace a Prediction Round-Trip
Follow one request from input to logged response.
Trace a Prediction Round-Trip is a free MLOps Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MLOps Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Follow One Request
Time to watch the whole loop work. You will follow a single prediction from a client request all the way to a logged response. 🔍
The Client Sends Input
A caller POSTs JSON to /predict. This is the raw input feature payload your model needs to make a decision.
curl -X POST localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"tenure": 12, "monthly_charges": 79.9}'Pydantic Validates
FastAPI parses the body against your schema. If a field is missing or the wrong type, Pydantic rejects it with a 422 before the model runs.
The Model Predicts
The validated row hits the loaded champion model. It computes a result in memory, no retraining and no registry call on the hot path.
pred = app.state.model.predict([[f.tenure, f.monthly_charges]])Log What Happened
Before responding, write a structured log line with the inputs, the prediction, and a timestamp. This is your audit trail.
import logging, json
logging.info(json.dumps({
"input": f.model_dump(),
"prediction": int(pred[0]),
}))Return the Response
FastAPI serializes your dict back to JSON and sends it with a 200. The client receives the prediction in milliseconds.
{"prediction": 1}Capture Latency
Wrap the call to measure how long it took. Logging latency per request is what later powers your monitoring dashboards.
import time
start = time.perf_counter()
# predict...
elapsed_ms = (time.perf_counter() - start) * 1000Tie Back to the Version
Log which model produced the answer. Recording the version means you can always say exactly which model made any past prediction.
{"model": "churn-classifier", "version": 3}The Loop Closed
Train, register, promote, serve, predict, log: one request just walked the entire pipeline you built. That is end-to-end MLOps. 🎯
Quick Check
Why log the input, prediction, and model version on every request?
Logs Feed Monitoring
Those logged round-trips become the raw material for the next stage: monitoring latency, error rates, and eventually input drift over time.
You Built a System
This is no longer a notebook. It is a traceable system where every prediction can be explained and reproduced from end to end.
Recap: The Full Round-Trip
You traced one request through validation, prediction, logging, and response, tying it back to a model version. That closes your first end-to-end flow. ✅
Frequently asked questions
Is the “Trace a Prediction Round-Trip” lesson free?
Yes — the full text of “Trace a Prediction Round-Trip” is free to read here on the web, and the MLOps Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MLOps Academy course, upgrade to CoddyKit PRO.
What will I learn in “Trace a Prediction Round-Trip”?
Follow one request from input to logged response. You practise MLOps Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start MLOps Academy?
No prior experience is required. MLOps Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Trace a Prediction Round-Trip” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this MLOps Academy lesson?
Yes. Every MLOps Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Train and Log to the Registry
- Promote the Best Model to Production
- Serve the Production Model
- Trace a Prediction Round-Trip