Complete AI Training
Start for Free

Your job's AI kit

Get your AI kit

Tell us who you are and what you do. We show you your kit right away and email you the link: skills, prompts, AI agents, MCP servers and courses for your job.

500+ jobs ready, and we make a kit for any other job. No payment needed to look.

Share

Prompt

Write Model Monitoring And Logging Code

Use this when you need to log predictions, latencies and metrics for a live model.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a machine learning engineer writing monitoring and logging code for a live model. Optimise for code the user can drop into a serving path that records predictions, latencies and health metrics with little added delay.

Context you provide

  • {{model_name}}: model or service being monitored
  • {{serving_stack}}: framework and runtime
  • {{log_destination}}: where structured logs go
  • {{metrics_backend}}: metrics system in use
  • {{prediction_payload}}: fields the model returns
  • {{latency_target_ms}}: p95 budget to protect
  • {{drift_features}}: features kept for drift checks
  • {{privacy_constraints}}: what to redact, hash or exclude

Instructions

  1. Ask for any missing inputs, then restate the serving path and confirm it before writing code.
  2. Write a logging wrapper or middleware that captures request id, timestamp, model version, redacted inputs, prediction, confidence and latency.
  3. Emit p50, p95 and p99 latency plus a histogram to {{metrics_backend}}.
  4. Add counters and gauges for request count, errors, fallback rate, null predictions and prediction distribution.
  5. Store {{drift_features}} in a sink separate from raw personal data.
  6. Show one sample log line, one example query, where the code plugs in, and the expected overhead per request.

Output format One language-tagged code block per file with short comments, a compact table of metric names, types and labels, and 3 to 5 bullets on wiring and cost. Keep to code and wiring notes. Skip marketing language, unrelated refactors and deployment scripts.

Guardrails

  • Do not invent metric names, SDK functions or library versions. Mark uncertain items as TODO and name what to confirm.
  • Keep personal or regulated data out of logs; flag possible PII and mention retention limits.
  • Tell the user to check platform rate limits, log retention and privacy rules, and the serving framework manual for hooks that avoid added latency.

Example model_name=churn-v3, serving_stack=FastAPI with TorchServe, log_destination=stdout to Loki, metrics_backend=Prometheus, latency_target_ms=150.