Evaluation, tracing, and iteration · Lesson 2 of 3
MLflow tracing and GenAI observability
Trace application steps to diagnose latency, retrieval, and model behavior.
Lesson
Tracing records the path of a request through an application, such as preprocessing, retrieval, model calls, and tool execution. A trace can help identify whether a poor answer came from missing source material, prompt construction, a slow dependency, or output validation. MLflow provides GenAI tracing and evaluation capabilities; current APIs and workspace setup can change, so use the version-matched Databricks and MLflow documentation.
Instrument useful metadata such as model version, prompt version, duration, and safe retrieval identifiers. Apply redaction and access controls before collecting prompts or outputs, since traces may contain sensitive data. Define retention and sampling policies, and avoid logging credentials or unrestricted user content.
Instrument spans around retrieval, prompt assembly, model invocation, tool use, and response validation. Useful metadata includes model and prompt versions, elapsed time, token counts where available, and safe source identifiers. Traces can contain user text and retrieved private material, so choose redaction, access controls, sampling, and retention before enabling broad collection. Avoid storing credentials or unrestricted payloads by default. During an incident, compare traces from successful and failed requests to locate the earliest divergence. Validate instrumentation with a deliberately slow dependency and a rejected output before relying on it operationally.
Implementation drill: trace one representative request through the stages in the diagram. Write down what enters each stage, what output or evidence it produces, and which identity is allowed to perform it. Then test an empty input, an unauthorized request, a dependency timeout, and an unexpected result. For each case, state whether the application should retry, reject, abstain, or ask a person for help. Keep the observed failure as a regression example so changes to prompts, models, data, or code can be checked against the same behavior.
Practice task: What should be excluded from application traces?
Visual guide
Trace a request across components
-
Step 01
Instrument
Trace retrieval, model, and tool steps.
-
Step 02
Redact
Protect sensitive trace content.
-
Step 03
Inspect
Locate latency and quality failures.
-
Step 04
Act
Fix the failing component.
Code examples
Trace useful, non-secret metadata
PYTHON
trace_metadata = {
'model_version': 'candidate-3',
'prompt_version': 'support-answer-v2',
'retrieved_document_ids': ['policy-42'],
'duration_ms': 840,
}
# Do not add API keys or unrestricted private text.
Expected output
Metadata can support diagnosis without recording credentials.
Key points
- Trace component boundaries to locate latency and quality problems.
- Keep trace data governed because prompts and outputs can be sensitive.
- Use version-compatible MLflow documentation for current APIs.
Check your understanding
Practice
Your learning progress