Skip to content

Set a readable root-span request and response - #31

Open
adamgurary wants to merge 2 commits into
mlflow:mainfrom
adamgurary:readable-root-span
Open

Set a readable root-span request and response#31
adamgurary wants to merge 2 commits into
mlflow:mainfrom
adamgurary:readable-root-span

Conversation

@adamgurary

Copy link
Copy Markdown
Contributor

Fixes #29

Context

This issue is one finding from a hands-on evaluation (a Critical User Journey run) of building, tracing, and improving an agent that runs off Databricks. The agent is a LangGraph rebuild of a customer-notes workflow. It runs on a laptop and calls the Databricks Foundation Model API endpoint databricks-claude-opus-4-8. Its MLflow traces are written to Unity Catalog.

Full writeup:

Environment

  • MLflow 3.14.0, LangGraph 1.2.7, LangChain 1.3.11, databricks-langchain 0.17.0, databricks-sdk 0.94.0, openai 2.24.0, Python 3.12.
  • Databricks workspace: logfood (adb-2548836972759138). SQL warehouse 79415a9aea7a3a7e.
  • MLflow experiment: customer-notes-agent-uc (id 2824204872263693).
  • UC trace location: catalog home_adam_gurary, schema personal_agents, table prefix customer_notes.
  • Per run: roughly 1.6M input tokens across about 14 to 16 LLM calls.

Instrumentation skill should produce a readable root-span request and response

Summary

When a coding agent used the MLflow instrumentation skills to trace a LangGraph agent, the top of the trace showed an unreadable blob instead of the run inputs and outputs. The @mlflow.trace decorator on the entry point auto-recorded the compiled LangGraph object as the request and the entire final state dict as the response. The root span showed neither the customer name going in nor the note coming out.

Steps to reproduce

  1. Ask a coding agent to instrument a LangGraph agent's entry point with @mlflow.trace per the skills.
  2. Run the agent, open the trace, look at the root span request and response.

Actual behavior

The root-span request was the Python repr of the compiled graph object. The root-span response was the full accumulated state dictionary (transcript plus all research plus draft). Both were unreadable in the UI.

Root cause

The skill applied @mlflow.trace to a function whose input is a large framework object and whose output is a large state dict, without guiding the agent to record a compact, human-readable summary instead.

Expected behavior and proposed fix

The MLflow instrumentation skills should teach the coding agent to set a compact, readable request and response on the root span, rather than letting @mlflow.trace capture raw framework objects. For a LangGraph agent, that means the meaningful inputs (the customer and date) and the meaningful outputs (the output path and a short preview). The goal is that the trace reads well in the UI by default.

Evidence and references

Fixed in the agent by hand-setting compact root-span fields (commit 64c0d647d). See the walkthrough linked above.

Signed-off-by: Adam Gurary <guraryadam@gmail.com>
span.set_outputs() inside a @mlflow.trace body is overwritten by the
decorator after the function exits (last-write-wins). Empirically
confirmed on MLflow 3.11.1.dev0: the old example left root span outputs
at 58k chars. Two correct patterns now shown: update_current_trace
(request_preview/response_preview) for compact Trace list UI previews
while keeping the decorator, and a manual start_span entry point for
compact storage on the root span itself. Also fixes None-safety on
note_text slice: (state.get("note_text") or "")[:200].

Signed-off-by: Adam Gurary <guraryadam@gmail.com>
@adamgurary
adamgurary force-pushed the readable-root-span branch from 1aa0c12 to ef4ef3e Compare July 30, 2026 23:33
@adamgurary

Copy link
Copy Markdown
Contributor Author

Hi — just rebased this onto the latest main (was 12 commits behind). The PR adds two reference commits to the databricks-mlflow-evaluation skill: one guiding agents to set a readable root-span request and response, and one teaching the correct override pattern (using update_current_trace vs span.set_outputs() which is overwritten by the decorator). No CI gaps to resolve. Would appreciate a review when you have a moment — happy to address any feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Instrumentation skill should produce a readable root-span request and response

1 participant